home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 June / CHIPCD_6_2000.iso / software / cad / t425l1e / t425l1e.exe / _001870_ / EXPORT_.C
C/C++ Source or Header  |  1997-06-14  |  13KB  |  347 lines

  1. //------------------------------------------------------------------------------------------------------
  2. // Name       : export_.c
  3. // Date       : 05.03.1997     Author : SM           System : Win32
  4. //------------------------------------------------------------------------------------------------------
  5. // This file contains the language-independent implementation of the module EXPORT_.DLL. All texts and
  6. // resources that are language-dependent are located in an additional EXPORT.DLL, whose sources can be
  7. // found in the subdirectories \E (for English) and \D (for German).
  8. //------------------------------------------------------------------------------------------------------
  9.  
  10. #define TOSO_MODULE_VERSION     420             // Required version of Toso Interface
  11.  
  12. //------------------------------------------------------------------------------------------------------
  13.  
  14. #define USER_DATA_ID              "1.00-1996-11-20"
  15. #define TXT_ID_HEADER           "TommySoftware TXT 1.10"
  16.  
  17. //------------------------------------------------------------------------------------------------------
  18.  
  19. #include        "windows.h"
  20. #include        "windowsx.h"
  21. #include        "stdlib.h"
  22. #include        "stdio.h"
  23. #include        "math.h"
  24.  
  25. #include        "e:\release4\tosoapi4.h"        // Toso Interface Definitions
  26. #include        "dialog.h"
  27.  
  28. //------------------------------------------------------------------------------------------------------
  29.  
  30. typedef struct {
  31.   STR32         TimeStamp;
  32.  
  33.   FILENAME      FileName;
  34. } INF_HEADER;
  35.  
  36. //------ Language-dependent texts in EXPORT.DLL --------------------------------------------------------
  37.  
  38. DLL_IMPORT LPSTR
  39.         eStartUpText    [],
  40.         eDialogText     [],
  41.         eMessageText    [];
  42.  
  43. //------------------------------------------------------------------------------------------------------
  44.  
  45. static  HINSTANCE       hInstDLL,               // Instance handle of the main DLL
  46.                         hLanguage,              // Instance handle of the language DLL
  47.                         hGlobalInst;            // Instance handle of the serving application
  48. static  HWND            hGlobalWnd;             // Main window handle of the serving application
  49.  
  50. //------------------------------------------------------------------------------------------------------
  51.  
  52. static  HBITMAP         hBitmap;
  53. static  INF_HEADER      INFHeader;
  54. static  int             gError;                 // Current error status ( 0 = OK )
  55.  
  56. //------------------------------------------------------------------------------------------------------
  57.  
  58. BOOL ModuleLoadSettings( void )
  59. {
  60.   BOOL          Result = FALSE;
  61.  
  62.   if( TosoProfileReadKeyOpen( "EXPORT", FALSE ) ) {
  63.     if( TosoProfileReadData( "Init", (LPBYTE) &INFHeader, sizeof( INFHeader ) ) )
  64.       Result = TRUE;
  65.     TosoProfileReadKeyClose();
  66.  
  67.     INFHeader.TimeStamp[31] = 0x00;
  68.     if( lstrcmp( INFHeader.TimeStamp, USER_DATA_ID ) )
  69.       Result = FALSE;
  70.   }
  71.  
  72.   if( !Result ) {
  73.     lstrcpy( INFHeader.FileName, eDialogText[1] );
  74.   }
  75.   return( Result );
  76. }
  77.  
  78. //------------------------------------------------------------------------------------------------------
  79.  
  80. BOOL ModuleSaveSettings( void )
  81. {
  82.   BOOL          Result = FALSE;
  83.  
  84.   if( TosoProfileWriteKeyOpen( "EXPORT", FALSE ) ) {
  85.     lstrcpy( INFHeader.TimeStamp, USER_DATA_ID );
  86.     if( TosoProfileWriteData( "Init", (LPBYTE) &INFHeader, sizeof( INFHeader ) ) )
  87.       Result = TRUE;
  88.     TosoProfileWriteKeyClose();
  89.   }
  90.   return( Result );
  91. }
  92.  
  93. //------------------------------------------------------------------------------------------------------
  94. // This procedure is used as callback procedure for an object enumeration based on the interface
  95. // procedure TosoEnumerateAll(). It simply runs through of the object described in EnumData and write
  96. // the coordinates of all its definition points to the currently open file.
  97. // After each coordinate pair written, it also updates the current progress indicator and checks whether
  98. // the user has pressed the Cancel button to stop the export.
  99.  
  100. BOOL ModuleEnumCallback( const ENUMDEF_DATA* EnumData )
  101. {
  102.   DUMMYSTR      Text1, Text2;
  103.   int           Count;
  104.  
  105.   switch( EnumData->EnumData ) {
  106.     case ENUMDATA_CURVE:
  107.     case ENUMDATA_AREA:
  108.     case ENUMDATA_MARK:
  109.       for( Count = 0; Count < EnumData->EnumCount; Count++ ) {
  110.         TosoFileWriteShort      ( DB_POINT_ANY );
  111.         TosoFileWriteCommaDouble( EnumData->PointPtr[Count].x );
  112.         TosoFileWriteCommaDouble( EnumData->PointPtr[Count].y );
  113.         TosoFileWriteSemi();
  114.  
  115.         if( TosoFileWriteError() ) {
  116.           gError = 1;
  117.           break;
  118.         }
  119.  
  120.         wsprintf( Text1, eDialogText[3], TosoFileWriteCurrentLine() );
  121.         wsprintf( Text2, eDialogText[4], ( TosoFileWriteCurrentSize() + 1023 ) / 1024 );
  122.         TosoDialogUpdateProgress( Text1, Text2, NOPARAM, NOPARAM );
  123.  
  124.         if( TosoDialogIsCanceled() ) {
  125.           gError = 999;
  126.           break;
  127.         }
  128.       }
  129.       break;
  130.   }
  131.   return( !gError );
  132. }
  133.  
  134. //------------------------------------------------------------------------------------------------------
  135. // This procedure performs the export. It starts the object enumeration (which writes coordinate pairs
  136. // to the file).
  137. // In addition, it initializes and display a progress indicator window to inform the user about the
  138. // current progress and to allow him to cancel the export. Since the final file size is not known
  139. // in advance, the progress indicator does not include a percent bar.
  140.  
  141. void ModuleExport( HANDLE FileHandle, const LPSTR FileName, int Flag )
  142. {
  143.   FILENAME      FileName2;
  144.   DUMMYSTR      DummyStr;
  145.  
  146.   gError = 0;
  147.  
  148.   if( !TosoFileWriteInitDisk( FileHandle ) ) {
  149.     gError = 1;
  150.     return;
  151.   }
  152.  
  153.   TosoFileSplitName( FileName, NULL, FileName2 );
  154.   wsprintf( DummyStr, eDialogText[2], FileName2 );
  155.   TosoDialogShowProgress( eDialogText[0], DummyStr, FALSE );
  156.  
  157.   TosoFileWriteTextData( TXT_ID_HEADER );
  158.   TosoFileWriteSemi();
  159.  
  160.   TosoEnumerateAll( TosoDrawingGetActive(), Flag, Flag,
  161.                     ENUMMODE_PLAIN | ENUMMODE_LINES | ENUMMODE_LINETYPES,
  162.                     (TOSOENUMOBJECT_PROC) ModuleEnumCallback );
  163.  
  164.   TosoFileWriteShort( DB_END );
  165.   TosoFileWriteSemi();
  166.  
  167.   if( !TosoFileWriteFlush() )
  168.     gError = 1;
  169.  
  170.   TosoFileWriteExit();
  171.   TosoDialogHideProgress();
  172. }
  173.  
  174. //------------------------------------------------------------------------------------------------------
  175. // This DLL entry procedure must exist in any DLL to be used in Win32. Since our DLL does all necessary
  176. // initialization in its TosoModuleInit() procedure, this procedure is quite empty.
  177.  
  178. BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD Reason, LPVOID Dummy )
  179. {
  180.   switch( Reason ) {
  181.     case DLL_PROCESS_ATTACH:
  182.       hInstDLL = hInstance;
  183.       break;
  184.  
  185.     case DLL_PROCESS_DETACH:
  186.       hInstDLL = NULL;
  187.       break;
  188.   }
  189.   return( TRUE );
  190. }
  191.  
  192. //------------------------------------------------------------------------------------------------------
  193. // This procedure is called when the module is loaded by the serving application. Its main tasks are:
  194. // - Checking whether it is compatible with the given InterfaceVersion
  195. // - Checking whether it is licensed to the given serial number (optional)
  196. // - Storing of the serving application's instance and main windows handle for further use
  197. // - Loading of the language-dependent library
  198. // - Filling in the module ID structure whose address is passed in ModuleID
  199. // - Loading of options from the registry database
  200. // - Loading profiles
  201. // - Allocating any static memory required
  202.  
  203. DLL_EXPORT int TosoModuleInit( const LPSTR SerialNumber, HINSTANCE hMainInst, HWND hMainWnd,
  204.                                                          int InterfaceVersion, MODULE_ID* ModuleID )
  205. {
  206.   if( InterfaceVersion < TOSO_MODULE_VERSION ) {
  207.     MessageBox( hMainWnd, eMessageText[0], eDialogText[0], MB_OK );
  208.     return( 0 );
  209.   }
  210.  
  211.   if( !lstrcmp( SerialNumber, "DEMO" ) )
  212.     return( 0 );
  213.  
  214.   hGlobalInst = hMainInst;
  215.   hGlobalWnd  = hMainWnd;
  216.  
  217.   hLanguage = LoadLibrary( "EXPORT.DLL" );
  218.   hBitmap = LoadBitmap( hLanguage, "IDB_COMMAND" );
  219.  
  220.   ModuleID->OwnerID    = DB_OWNER_TOSO;
  221.   ModuleID->ModuleID   = 0x2000;
  222.   ModuleID->ModuleCTRL = MODULECTRL_ALL;
  223.  
  224.   ModuleID->ModuleProc.InputPointInitProc = (TOSOINPUTPOINTINIT_PROC) NULL;
  225.   ModuleID->ModuleProc.InputPointMoveProc = (TOSOINPUTPOINTMOVE_PROC) NULL;
  226.   ModuleID->ModuleProc.InputPointExitProc = (TOSOINPUTPOINTEXIT_PROC) NULL;
  227.   ModuleID->ModuleProc.InputDisplayProc   = (TOSOINPUTDISPLAY_PROC)   NULL;
  228.   ModuleID->ModuleProc.InputParameterProc = (TOSOINPUTPARAMETER_PROC) NULL;
  229.   ModuleID->ModuleProc.InputCancelProc    = (TOSOINPUTCANCEL_PROC)    NULL;
  230.   ModuleID->ModuleProc.InputFinishProc    = (TOSOINPUTFINISH_PROC)    NULL;
  231.  
  232.   ModuleID->ModuleData.Type = MODULETYPE_EXPORT;
  233.  
  234.   ModuleID->ModuleData.InputData.CommandMode = COMMAND_DIRECT;
  235.   ModuleID->ModuleData.MenuData.MenuEntry   = eStartUpText[1];
  236.   ModuleID->ModuleData.MenuData.Description = eStartUpText[2];
  237.  
  238.   ModuleID->ModuleData.IconHandle  = hBitmap;
  239.   ModuleID->ModuleData.IconXOffset = 0;
  240.   ModuleID->ModuleData.IconYOffset = 0;
  241.   ModuleID->ModuleData.IconMode    = 0;
  242.  
  243.   ModuleID->CommandData = NULL;
  244.   ModuleID->VendorData  = NULL;
  245.  
  246.   ModuleID->FileType      = eStartUpText[4];
  247.   ModuleID->FileExtension = eStartUpText[5];
  248.   ModuleID->FileDefault   = eStartUpText[6];
  249.  
  250.   ModuleLoadSettings();
  251.  
  252.   return( TOSO_MODULE_VERSION );
  253. }
  254.  
  255. //------------------------------------------------------------------------------------------------------
  256. // This procedure is called when the module is removed by the serving application. Its main tasks are:
  257. // - Checking whether anything is to be saved. If so, it should display a message information the user
  258. //   about it and allowing him to save those changes.
  259. // - Freeing of all statically allocated memory.
  260. // If this procedure return FALSE, the serving application will not be able to terminate. So please, do
  261. // only return FALSE if shutting down the module now would severely damage or destroy user data.
  262.  
  263. DLL_EXPORT BOOL TosoModuleExit( void )
  264. {
  265.   ModuleSaveSettings();
  266.  
  267.   DeleteBitmap( hBitmap );
  268.  
  269.   return( TRUE );
  270. }
  271.  
  272. //------------------------------------------------------------------------------------------------------
  273. // This procedure is called when the user wants to save a non-TVG drawing using the File>Save as command.
  274. // For an export filter, its task is simply to save the file.
  275.  
  276. DLL_EXPORT BOOL TosoModuleExport( const LPSTR FileName, int Flag )
  277. {
  278.   HANDLE        FileHandle;
  279.   BOOL          Result = FALSE;
  280.     
  281.   if( TosoFileCreate( &FileHandle, FileName ) ) {
  282.     
  283.     ModuleExport( FileHandle, FileName, Flag );
  284.     
  285.     TosoFileClose( FileHandle );
  286.     switch( gError ) {
  287.       case 999:
  288.         TosoFileDelete( FileName );
  289.         MessageBox( hGlobalWnd, eMessageText[2], eDialogText[0], MB_OK );
  290.         Result = TRUE;
  291.         break;
  292.     
  293.       case 0:
  294.         Result = TRUE;
  295.         break;
  296.     
  297.       default:
  298.         TosoFileDelete( FileName );
  299.         MessageBox( hGlobalWnd, eMessageText[4], eDialogText[0], MB_OK );
  300.         Result = FALSE;
  301.         break;
  302.     }
  303.   }
  304.   return( Result );
  305. }
  306.  
  307. //------------------------------------------------------------------------------------------------------
  308. // This procedure is called when a module's command is chosen by the user. For an export filter, its
  309. // main tasks are:
  310. // - Parameter editing
  311. // - Help file display
  312.  
  313. DLL_EXPORT BOOL TosoModuleCommand( int CommandID, int ExecMode )
  314. {
  315.   switch( ExecMode ) {                  // Check which type of action is requested
  316.     case MODULEEXEC_HELP:               // Display the corresponding help topic
  317.       {
  318.         FILENAME    FileName;
  319.         TosoFileApplicationPath( "EXPORT.HLP", FileName );
  320.         WinHelp( hGlobalWnd, FileName, HELP_CONTEXT, 1 );
  321.       }
  322.       return( TRUE );
  323.  
  324.     case MODULEEXEC_USER:               // Edit the options
  325.       {
  326.         DUMMYSTR    Text1, Text2;
  327.         TOSO_GET_BUILD_DATE( Text2 );
  328.         wsprintf( Text1, eStartUpText[0], Text2 );
  329.         MessageBox( GetActiveWindow(), Text1, eDialogText[0], MB_OK );
  330.       }
  331.       return( TRUE );
  332.  
  333.     case MODULEEXEC_SYSTEM:             // Execute the command
  334.       // Nothing to do here...
  335.       break;
  336.  
  337.     case MODULEEXEC_GET_PROFILE:        // Read drawing-dependent data
  338.       // Nothing to do here...
  339.       break;
  340.  
  341.     case MODULEEXEC_SET_PROFILE:        // Write drawing-dependent data
  342.       // Nothing to do here...
  343.       break;
  344.   }
  345.   return( FALSE );
  346. }
  347.