/*
* ------------------------------------------
*  File Box Functions
* ------------------------------------------
*/

#include <windows.h>
#include <commdlg.h>

static OPENFILENAME ofn;


static TCHAR szFilter1[] =
       "Coastlines, Islands And Lakes (CIL.CBD)\0cil.cbd\0" \
       "Rivers (RIV.CBD)\0riv.cbd\0" \
       "Int. Political Boundaries (BDY.CBD)\0bdy.cbd\0" \
       "Nat. Political Boundaries (PBY.CBD)\0pby.cbd\0" \
               "All Files (*.*)\0*.*\0\0";

static TCHAR szFilter2[] =
       "Configuration Files (*.CFG)\0*.cfg\0" \
       "All Files (*.*)\0*.*\0\0";



void FileInitialize(int mode, char *initialDir)
{
       ofn.lStructSize       = sizeof (OPENFILENAME);
       ofn.hwndOwner         = NULL;
       ofn.hInstance         = NULL;
       ofn.lpstrFilter       = szFilter1;
       if (mode)
               ofn.lpstrFilter   = szFilter2;
       ofn.lpstrCustomFilter = NULL;
       ofn.nMaxCustFilter    = 0;
       ofn.nFilterIndex      = 0;
       ofn.lpstrFile         = NULL;          // Set in Open and Close functions
       ofn.nMaxFile          = MAX_PATH;
       ofn.lpstrFileTitle    = NULL;          // Set in Open and Close functions
       ofn.nMaxFileTitle     = MAX_PATH;
       ofn.lpstrInitialDir   = initialDir;
       ofn.lpstrTitle        = NULL;
       ofn.Flags             = 0;             // Set in Open and Close functions
       ofn.nFileOffset       = 0;
       ofn.nFileExtension    = 0;
       ofn.lpstrDefExt       = "cil";
       ofn.lCustData         = 0L;
       ofn.lpfnHook          = NULL;
       ofn.lpTemplateName    = NULL;
}


void DirInitialize(void)
{
       static TCHAR szFilter[] = "All Files (*.*)\0*.*\0\0";

       ofn.lStructSize       = sizeof (OPENFILENAME);
       ofn.hwndOwner         = NULL;
       ofn.hInstance         = NULL;
       ofn.lpstrFilter       = szFilter;
       ofn.lpstrCustomFilter = NULL;
       ofn.nMaxCustFilter    = 0;
       ofn.nFilterIndex      = 0;
       ofn.lpstrFile         = NULL;          // Set in Open and Close functions
       ofn.nMaxFile          = MAX_PATH;
       ofn.lpstrFileTitle    = NULL;          // Set in Open and Close functions
       ofn.nMaxFileTitle     = MAX_PATH;
       ofn.lpstrInitialDir   = NULL;
       ofn.lpstrTitle        = NULL;
       ofn.Flags             = 0;             // Set in Open and Close functions
       ofn.nFileOffset       = 0;
       ofn.nFileExtension    = 0;
       ofn.lpstrDefExt       = "cil";
       ofn.lCustData         = 0L;
       ofn.lpfnHook          = NULL;
       ofn.lpTemplateName    = NULL;
}


BOOL FileOpenDlg(HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName, int mode)
{
       ofn.hwndOwner         = hwnd;
       ofn.lpstrFile         = pstrFileName;
       ofn.lpstrFileTitle    = pstrTitleName;
       ofn.Flags             = OFN_HIDEREADONLY | OFN_CREATEPROMPT;

       return GetOpenFileName (&ofn);
}


BOOL FileSaveDlg(HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName, int mode)
{
       ofn.hwndOwner         = hwnd;
       ofn.lpstrFile         = pstrFileName;
       ofn.lpstrFileTitle    = pstrTitleName;
       ofn.Flags             = OFN_OVERWRITEPROMPT;

       return GetSaveFileName (&ofn);
}


BOOL DirOpenDlg(HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitle)
{
       ofn.hwndOwner         = hwnd;
       ofn.lpstrFile         = pstrFileName;
       ofn.lpstrTitle        = pstrTitle;
       ofn.Flags             = OFN_HIDEREADONLY | OFN_CREATEPROMPT;

       return GetOpenFileName (&ofn);
}