Rev 433 | 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 | |
35 | Boolean fileHasExtension(StandardFileReply* sfr, const char* extension) { |
||
36 | char name[MAX_PATH + 1]; |
||
433 | daniel-mar | 37 | // TODO: strcasecmp not defined in OpenWatcom 2.0 ? |
371 | daniel-mar | 38 | return sfr->nFileExtension && !strcasecmp(myp2cstrcpy(name, sfr->sfFile.name) + sfr->nFileExtension - 1, extension); |
39 | } |
||
40 | |||
259 | daniel-mar | 41 | Boolean choosefiletypes(StringPtr prompt,StandardFileReply *sfr,NavReplyRecord *reply, |
268 | daniel-mar | 42 | OSType types[],int ntypes,const char *lpstrFilter,HWND hwndOwner){ |
433 | daniel-mar | 43 | UNREFERENCED_PARAMETER(ntypes); |
259 | daniel-mar | 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 | |||
433 | daniel-mar | 52 | UNREFERENCED_PARAMETER(type); |
53 | UNREFERENCED_PARAMETER(reply); |
||
54 | |||
259 | daniel-mar | 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; |
||
268 | daniel-mar | 71 | }else{ |
72 | #ifdef DEBUG |
||
441 | daniel-mar | 73 | char s[100]; |
259 | daniel-mar | 74 | sprintf(s,"GetOpenFileName(): error %d",CommDlgExtendedError()); |
75 | dbg(s); |
||
268 | daniel-mar | 76 | #endif |
259 | daniel-mar | 77 | } |
78 | |||
79 | return sfr->sfGood = false; |
||
80 | } |
||
81 | |||
82 | Boolean putfile(StringPtr prompt,StringPtr fname,OSType fileType,OSType fileCreator, |
||
268 | daniel-mar | 83 | NavReplyRecord *reply,StandardFileReply *sfr, |
84 | const char *lpstrDefExt,const char *lpstrFilter,int nFilterIndex, |
||
85 | HWND hwndOwner){ |
||
259 | daniel-mar | 86 | OPENFILENAME ofn; |
87 | char file[MAX_PATH]; |
||
88 | char title[0x100]; |
||
89 | |||
433 | daniel-mar | 90 | UNREFERENCED_PARAMETER(fileCreator); |
91 | UNREFERENCED_PARAMETER(reply); |
||
92 | UNREFERENCED_PARAMETER(fileType); |
||
93 | |||
259 | daniel-mar | 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); |
||
369 | daniel-mar | 108 | sfr->nFileExtension = ofn.nFileExtension; |
259 | daniel-mar | 109 | return sfr->sfGood = true; |
268 | daniel-mar | 110 | }else{ |
111 | #ifdef DEBUG |
||
441 | daniel-mar | 112 | char s[100]; |
259 | daniel-mar | 113 | sprintf(s,"GetSaveFileName(): error %d",CommDlgExtendedError()); |
114 | dbg(s); |
||
268 | daniel-mar | 115 | #endif |
259 | daniel-mar | 116 | } |
117 | |||
118 | return sfr->sfGood = false; |
||
119 | } |
||
120 | |||
121 | OSErr completesave(NavReplyRecord *reply){ |
||
433 | daniel-mar | 122 | UNREFERENCED_PARAMETER(reply); |
259 | daniel-mar | 123 | return noErr; |
124 | } |