Subversion Repositories filter_foundry

Rev

Rev 433 | Rev 442 | 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.         // TODO: strcasecmp not defined in OpenWatcom 2.0 ?
  38.         return sfr->nFileExtension && !strcasecmp(myp2cstrcpy(name, sfr->sfFile.name) + sfr->nFileExtension - 1, extension);
  39. }
  40.  
  41. Boolean choosefiletypes(StringPtr prompt,StandardFileReply *sfr,NavReplyRecord *reply,
  42.                         OSType types[],int ntypes,const char *lpstrFilter,HWND hwndOwner){
  43.         UNREFERENCED_PARAMETER(ntypes);
  44.         return choosefile(prompt,sfr,reply,types[0],lpstrFilter,hwndOwner);
  45. }
  46.  
  47. Boolean choosefile(StringPtr prompt,StandardFileReply *sfr,NavReplyRecord *reply,OSType type,const char *lpstrFilter,HWND hwndOwner){
  48.         OPENFILENAME ofn;
  49.         char file[MAX_PATH]={0};
  50.         char title[0x100];
  51.  
  52.         UNREFERENCED_PARAMETER(type);
  53.         UNREFERENCED_PARAMETER(reply);
  54.  
  55.         ZeroMemory(&ofn, sizeof(ofn));
  56.  
  57.         ofn.lStructSize = sizeof(ofn);
  58.         ofn.hwndOwner = hwndOwner;
  59.         ofn.lpstrFilter = lpstrFilter ;
  60. //      ofn.nFilterIndex = 1;
  61.         ofn.lpstrFile = file;
  62.         ofn.nMaxFile = MAX_PATH;
  63.         ofn.lpstrTitle = myp2cstrcpy(title,prompt);
  64.         ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
  65. //      ofn.lpstrDefExt = lpstrDefExt;
  66.  
  67.         if(GetOpenFileName(&ofn)){
  68.                 myc2pstrcpy(sfr->sfFile.name,file);
  69.                 sfr->nFileExtension = ofn.nFileExtension;
  70.                 return sfr->sfGood = true;
  71.         }else{
  72.                 #ifdef DEBUG
  73.                 char s[100];
  74.                 sprintf(s,"GetOpenFileName(): error %d",CommDlgExtendedError());
  75.                 dbg(s);
  76.                 #endif
  77.         }
  78.  
  79.         return sfr->sfGood = false;
  80. }
  81.  
  82. Boolean putfile(StringPtr prompt,StringPtr fname,OSType fileType,OSType fileCreator,
  83.                 NavReplyRecord *reply,StandardFileReply *sfr,
  84.                 const char *lpstrDefExt,const char *lpstrFilter,int nFilterIndex,
  85.                 HWND hwndOwner){
  86.         OPENFILENAME ofn;
  87.         char file[MAX_PATH];
  88.         char title[0x100];
  89.  
  90.         UNREFERENCED_PARAMETER(fileCreator);
  91.         UNREFERENCED_PARAMETER(reply);
  92.         UNREFERENCED_PARAMETER(fileType);
  93.  
  94.         ZeroMemory(&ofn, sizeof(ofn));
  95.  
  96.         ofn.lStructSize = sizeof(ofn);
  97.         ofn.hwndOwner = hwndOwner;
  98.         ofn.lpstrFilter = lpstrFilter;
  99.         ofn.nFilterIndex = nFilterIndex;
  100.         ofn.lpstrFile = myp2cstrcpy(file,fname);
  101.         ofn.nMaxFile = MAX_PATH;
  102.         ofn.lpstrTitle = myp2cstrcpy(title,prompt);
  103.         ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
  104.         ofn.lpstrDefExt = lpstrDefExt;
  105.  
  106.         if(GetSaveFileName(&ofn)){
  107.                 myc2pstrcpy(sfr->sfFile.name,file);
  108.                 sfr->nFileExtension = ofn.nFileExtension;
  109.                 return sfr->sfGood = true;
  110.         }else{
  111.                 #ifdef DEBUG
  112.                 char s[100];
  113.                 sprintf(s,"GetSaveFileName(): error %d",CommDlgExtendedError());
  114.                 dbg(s);
  115.                 #endif
  116.         }
  117.  
  118.         return sfr->sfGood = false;
  119. }
  120.  
  121. OSErr completesave(NavReplyRecord *reply){
  122.         UNREFERENCED_PARAMETER(reply);
  123.         return noErr;
  124. }
  125.