]> git.saurik.com Git - wxWidgets.git/blob - src/msw/mslu.cpp
ec882a9d986d5b11e0dbab49caf664efa08b561c
[wxWidgets.git] / src / msw / mslu.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/mslu.cpp
3 // Purpose: Fixes for bugs in MSLU
4 // Author: Vaclav Slavik
5 // Modified by:
6 // Created: 2002/02/17
7 // RCS-ID: $Id$
8 // Copyright: (c) 2002 Vaclav Slavik
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #include <dir.h>
18 #endif
19
20 #ifndef WX_PRECOMP
21 #include "wx/utils.h"
22 #endif
23
24 #define wxHAS_HUGE_FILES
25
26 //------------------------------------------------------------------------
27 // Check for use of MSLU
28 //------------------------------------------------------------------------
29
30 #if wxUSE_BASE
31
32 bool WXDLLIMPEXP_BASE wxUsingUnicowsDll()
33 {
34 #if wxUSE_UNICODE_MSLU
35 return (wxGetOsVersion() == wxOS_WINDOWS_9X);
36 #else
37 return false;
38 #endif
39 }
40
41 #endif // wxUSE_BASE
42
43
44 #if wxUSE_UNICODE_MSLU
45
46 //------------------------------------------------------------------------
47 //
48 // NB: MSLU only covers Win32 API, it doesn't provide Unicode implementation of
49 // libc functions. Unfortunately, some of MSVCRT wchar_t functions
50 // (e.g. _wopen) don't work on Windows 9x, so we have to workaround it
51 // by calling the char version. We still want to use wchar_t version on
52 // NT/2000/XP, though, because they allow for Unicode file names.
53 //
54 // Moreover, there are bugs in unicows.dll, of course. We have to
55 // workaround them, too.
56 //
57 //------------------------------------------------------------------------
58
59 #include "wx/msw/private.h"
60 #include "wx/msw/mslu.h"
61
62 #include <stdio.h>
63 #include <io.h>
64 #include <sys/stat.h>
65
66 #ifdef __VISUALC__
67 #include <direct.h>
68 #endif
69
70 // Undef redirection macros defined in wx/msw/wrapwin.h:
71 #undef DrawStateW
72 #undef GetOpenFileNameW
73 #undef GetSaveFileNameW
74
75 //------------------------------------------------------------------------
76 // Wrongly implemented functions from unicows.dll
77 //------------------------------------------------------------------------
78
79 #if wxUSE_GUI
80
81 WXDLLEXPORT int wxMSLU_DrawStateW(WXHDC dc, WXHBRUSH br, WXFARPROC outputFunc,
82 WXLPARAM lData, WXWPARAM wData,
83 int x, int y, int cx, int cy,
84 unsigned int flags)
85 {
86 // VS: There's yet another bug in MSLU: DrawStateW behaves like if it was
87 // expecting char*, not wchar_t* input. We have to use DrawStateA
88 // explicitly.
89
90 if ( wxUsingUnicowsDll() )
91 {
92 return DrawStateA((HDC)dc, (HBRUSH)br, (DRAWSTATEPROC)outputFunc,
93 (LPARAM)(const char*)
94 wxConvLocal.cWX2MB((const wxChar*)lData),
95 wData, x, y, cx, cy, flags);
96 }
97 else
98 {
99 return DrawStateW((HDC)dc, (HBRUSH)br, (DRAWSTATEPROC)outputFunc,
100 lData, wData, x, y, cx, cy, flags);
101 }
102 }
103
104 static void wxFixOPENFILENAME(LPOPENFILENAME ofn)
105 {
106 #ifdef OFN_EXPLORER
107 // VS: there's a bug in unicows.dll - when multiple files are selected,
108 // of.nFileOffset doesn't point to the first filename but rather to
109 // the last component of directory name. This bug is known to MSLU
110 // developers, but they are not going to fix it: "this is a true
111 // limitation, that we have decided to live with" and "working
112 // harder on this case just did not seem worth the effort"...
113 //
114 // Our only option is to try to fix it ourselves:
115
116 if ( (ofn->Flags & OFN_ALLOWMULTISELECT) &&
117 ofn->lpstrFile[ofn->nFileOffset-1] != wxT('\0') )
118 {
119 if ( wxDirExists(ofn->lpstrFile) )
120 {
121 // 1st component is dir => multiple files selected
122 ofn->nFileOffset = wxStrlen(ofn->lpstrFile)+1;
123 }
124 }
125 #endif // OFN_EXPLORER
126 }
127
128 WXDLLEXPORT int wxMSLU_GetOpenFileNameW(void *ofn)
129 {
130 int ret = GetOpenFileName((LPOPENFILENAME)ofn);
131 if ( wxUsingUnicowsDll() && ret != 0 )
132 wxFixOPENFILENAME((LPOPENFILENAME)ofn);
133 return ret;
134 }
135
136 WXDLLEXPORT int wxMSLU_GetSaveFileNameW(void *ofn)
137 {
138 int ret = GetSaveFileName((LPOPENFILENAME)ofn);
139 if ( wxUsingUnicowsDll() && ret != 0 )
140 wxFixOPENFILENAME((LPOPENFILENAME)ofn);
141 return ret;
142 }
143
144 #endif // wxUSE_GUI
145
146 //------------------------------------------------------------------------
147 // Missing libc file manipulation functions in Win9x
148 //------------------------------------------------------------------------
149
150 #if wxUSE_BASE
151
152 WXDLLIMPEXP_BASE int wxMSLU__wrename(const wchar_t *oldname,
153 const wchar_t *newname)
154 {
155 if ( wxUsingUnicowsDll() )
156 return rename(wxConvFile.cWX2MB(oldname), wxConvFile.cWX2MB(newname));
157 else
158 return _wrename(oldname, newname);
159 }
160
161 WXDLLIMPEXP_BASE int wxMSLU__wremove(const wchar_t *name)
162 {
163 if ( wxUsingUnicowsDll() )
164 return remove(wxConvFile.cWX2MB(name));
165 else
166 return _wremove(name);
167 }
168
169 WXDLLIMPEXP_BASE FILE* wxMSLU__wfopen(const wchar_t *name,const wchar_t* mode)
170 {
171 if ( wxUsingUnicowsDll() )
172 return fopen(wxConvFile.cWX2MB(name),wxConvFile.cWX2MB(mode));
173 else
174 return _wfopen(name,mode);
175 }
176
177 WXDLLIMPEXP_BASE FILE* wxMSLU__wfreopen(const wchar_t *name,
178 const wchar_t* mode,
179 FILE *stream)
180 {
181 if ( wxUsingUnicowsDll() )
182 return freopen(wxConvFile.cWX2MB(name), wxConvFile.cWX2MB(mode), stream);
183 else
184 return _wfreopen(name, mode, stream);
185 }
186
187 WXDLLIMPEXP_BASE int wxMSLU__wopen(const wchar_t *name, int flags, int mode)
188 {
189 if ( wxUsingUnicowsDll() )
190 return wxCRT_OpenA(wxConvFile.cWX2MB(name), flags, mode);
191 else
192 return wxCRT_OpenW(name, flags, mode);
193 }
194
195 WXDLLIMPEXP_BASE int wxMSLU__waccess(const wchar_t *name, int mode)
196 {
197 if ( wxUsingUnicowsDll() )
198 return wxCRT_AccessA(wxConvFile.cWX2MB(name), mode);
199 else
200 return wxCRT_AccessW(name, mode);
201 }
202
203 WXDLLIMPEXP_BASE int wxMSLU__wmkdir(const wchar_t *name)
204 {
205 if ( wxUsingUnicowsDll() )
206 return wxCRT_MkDirA(wxConvFile.cWX2MB(name));
207 else
208 return wxCRT_MkDirW(name);
209 }
210
211 WXDLLIMPEXP_BASE int wxMSLU__wrmdir(const wchar_t *name)
212 {
213 if ( wxUsingUnicowsDll() )
214 return wxCRT_RmDirA(wxConvFile.cWX2MB(name));
215 else
216 return wxCRT_RmDirW(name);
217 }
218
219 WXDLLIMPEXP_BASE int wxMSLU__wstat(const wchar_t *name, wxStructStat *buffer)
220 {
221 if ( wxUsingUnicowsDll() )
222 return wxCRT_StatA((const char*)wxConvFile.cWX2MB(name), buffer);
223 else
224 return wxCRT_StatW(name, buffer);
225 }
226
227 #endif // wxUSE_BASE
228
229 #endif // wxUSE_UNICODE_MSLU