Subversion Repositories filter_foundry

Rev

Rev 441 | Rev 444 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*
  2.     This file is part of a common library
  3.     Copyright (C) 2002-6 Toby Thain, toby@telegraphics.com.au
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18. */
  19.  
  20. /* Choose file dialog - Win32
  21.    (C) 2002 Toby Thain <toby@telegraphics.com.au> */
  22.  
  23. #include <string.h>
  24. #include <stdio.h>
  25.  
  26. #include <windows.h>
  27.  
  28. #include "world.h"
  29. #include "choosefile.h"
  30. #include "str.h"
  31. #include "dbg.h"
  32. #include "compat_string.h"
  33.  
  34.  
  35. Boolean fileHasExtension(StandardFileReply* sfr, const char* extension) {
  36.         char name[MAX_PATH + 1];
  37.         return sfr->nFileExtension && !strcasecmp(myp2cstrcpy(name, sfr->sfFile.name) + sfr->nFileExtension - 1, extension);
  38. }
  39.  
  40. Boolean choosefiletypes(StringPtr prompt,StandardFileReply *sfr,NavReplyRecord *reply,
  41.                         OSType types[],int ntypes,const char *lpstrFilter,HWND hwndOwner){
  42.         UNREFERENCED_PARAMETER(ntypes);
  43.         return choosefile(prompt,sfr,reply,types[0],lpstrFilter,hwndOwner);
  44. }
  45.  
  46. Boolean choosefile(StringPtr prompt,StandardFileReply *sfr,NavReplyRecord *reply,OSType type,const char *lpstrFilter,HWND hwndOwner){
  47.         OPENFILENAME ofn;
  48.         char file[MAX_PATH]={0};
  49.         char title[0x100];
  50.  
  51.         UNREFERENCED_PARAMETER(type);
  52.         UNREFERENCED_PARAMETER(reply);
  53.  
  54.         ZeroMemory(&ofn, sizeof(ofn));
  55.  
  56.         ofn.lStructSize = sizeof(ofn);
  57.         ofn.hwndOwner = hwndOwner;
  58.         ofn.lpstrFilter = lpstrFilter ;
  59. //      ofn.nFilterIndex = 1;
  60.         ofn.lpstrFile = file;
  61.         ofn.nMaxFile = MAX_PATH;
  62.         ofn.lpstrTitle = myp2cstrcpy(title,prompt);
  63.         ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
  64. //      ofn.lpstrDefExt = lpstrDefExt;
  65.  
  66.         if(GetOpenFileName(&ofn)){
  67.                 myc2pstrcpy(sfr->sfFile.name,file);
  68.                 sfr->nFileExtension = ofn.nFileExtension;
  69.                 return sfr->sfGood = true;
  70.         }else{
  71.                 #ifdef DEBUG
  72.                 char s[100];
  73.                 sprintf(s,"GetOpenFileName(): error %d",CommDlgExtendedError());
  74.                 dbg(s);
  75.                 #endif
  76.         }
  77.  
  78.         return sfr->sfGood = false;
  79. }
  80.  
  81. Boolean putfile(StringPtr prompt,StringPtr fname,OSType fileType,OSType fileCreator,
  82.                 NavReplyRecord *reply,StandardFileReply *sfr,
  83.                 const char *lpstrDefExt,const char *lpstrFilter,int nFilterIndex,
  84.                 HWND hwndOwner){
  85.         OPENFILENAME ofn;
  86.         char file[MAX_PATH];
  87.         char title[0x100];
  88.  
  89.         UNREFERENCED_PARAMETER(fileCreator);
  90.         UNREFERENCED_PARAMETER(reply);
  91.         UNREFERENCED_PARAMETER(fileType);
  92.  
  93.         ZeroMemory(&ofn, sizeof(ofn));
  94.  
  95.         ofn.lStructSize = sizeof(ofn);
  96.         ofn.hwndOwner = hwndOwner;
  97.         ofn.lpstrFilter = lpstrFilter;
  98.         ofn.nFilterIndex = nFilterIndex;
  99.         ofn.lpstrFile = myp2cstrcpy(file,fname);
  100.         ofn.nMaxFile = MAX_PATH;
  101.         ofn.lpstrTitle = myp2cstrcpy(title,prompt);
  102.         ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
  103.         ofn.lpstrDefExt = lpstrDefExt;
  104.  
  105.         if(GetSaveFileName(&ofn)){
  106.                 myc2pstrcpy(sfr->sfFile.name,file);
  107.                 sfr->nFileExtension = ofn.nFileExtension;
  108.                 return sfr->sfGood = true;
  109.         }else{
  110.                 #ifdef DEBUG
  111.                 char s[100];
  112.                 sprintf(s,"GetSaveFileName(): error %d",CommDlgExtendedError());
  113.                 dbg(s);
  114.                 #endif
  115.         }
  116.  
  117.         return sfr->sfGood = false;
  118. }
  119.  
  120. OSErr completesave(NavReplyRecord *reply){
  121.         UNREFERENCED_PARAMETER(reply);
  122.         return noErr;
  123. }
  124.