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