Subversion Repositories filter_foundry

Rev

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