/******************************************************************************/
/*                                                                            */
/*  SAVE_IMG - Get the name of an image file to write                         */
/*                                                                            */
/*  Note that save_img_file_init must be called once to initialize the        */
/*  ofn and structure.  We do it this way so that user changes become defaults*/
/*                                                                            */
/******************************************************************************/

#define STRICT
#include <windows.h>
#include <commctrl.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include "const.h"
#include "classes.h"
#include "funcdefs.h"
#include "lin.rh"
#include "extern.h"

static OPENFILENAME ofn ;

void save_img_file_init ()
{
   int i ;

   static char *szFiltstr =
      "BMP (*.BMP)|*.bmp|All files (*.*)|*.*|" ;
   static char szFilter[256] ;

   strcpy_s ( szFilter , szFiltstr ) ;
   for (i=0 ; szFilter[i] != 0 ; i++) {  // Replace | with NULL
      if (szFilter[i] == '|') // To guarantee all strings contiguous and
         szFilter[i] = 0 ;    // terminated with double NULL
      }

   ofn.lStructSize = sizeof(OPENFILENAME) ;
   ofn.hInstance = NULL ;
   ofn.lpstrFilter = &szFilter[0] ; // Filter defined above
   ofn.lpstrCustomFilter = NULL ;   // Do not allow user-defined filters
   ofn.nMaxCustFilter = 0 ;         // Ignored, but set it anyway
   ofn.nFilterIndex = 1 ;           // Strings in filter are origin 1
   ofn.lpstrFile = NULL ;           // Set in save_img_file
   ofn.lpstrFileTitle = NULL ;      // We do not need the simple name
   ofn.nMaxFileTitle = 0 ;          // Ignored, but set it anyway
   ofn.lpstrInitialDir = NULL ;     // Start with current directory
   ofn.lpstrTitle = "Blocks image file to write" ;
   ofn.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY |
               OFN_PATHMUSTEXIST | OFN_NONETWORKBUTTON ;
   ofn.lpstrDefExt = "bmp" ;        // Default extension if user types name
   ofn.lCustData = 0L ;             // Not used (for hook function only)
   ofn.lpfnHook = NULL ;            // No hook function
   ofn.lpTemplateName = NULL ;      // No resource template
}

int save_img_file ( HWND hwnd , char *name )
{
   ofn.hwndOwner = hwnd ;       // Handle of owner window
   ofn.lpstrFile = name ;       // Full name will go here
   ofn.nMaxFile = MAX_PATH-1 ;  // Length of that array

   return GetSaveFileName ( &ofn ) ;
}
