Subversion Repositories filter_foundry

Rev

Rev 442 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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