]>
Commit | Line | Data |
---|---|---|
136cb3c7 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: 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 | |
65571936 | 9 | // Licence: wxWindows licence |
136cb3c7 VS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
14f355c2 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
136cb3c7 VS |
13 | #pragma implementation |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
a3bb1d14 | 21 | #include <dir.h> |
136cb3c7 VS |
22 | #endif |
23 | ||
24 | #ifndef WX_PRECOMP | |
25 | #include "wx/defs.h" | |
26 | #endif | |
27 | ||
28 | #if wxUSE_UNICODE_MSLU | |
29 | ||
30 | //------------------------------------------------------------------------ | |
31 | // | |
32 | // NB: MSLU only covers Win32 API, it doesn't provide Unicode implementation of | |
33 | // libc functions. Unfortunately, some of MSVCRT wchar_t functions | |
34 | // (e.g. _wopen) don't work on Windows 9x, so we have to workaround it | |
35 | // by calling the char version. We still want to use wchar_t version on | |
36 | // NT/2000/XP, though, because they allow for Unicode file names. | |
37 | // | |
b36de7d0 | 38 | // Moreover, there are bugs in unicows.dll, of course. We have to |
136cb3c7 VS |
39 | // workaround them, too. |
40 | // | |
41 | //------------------------------------------------------------------------ | |
42 | ||
43 | #include "wx/msw/private.h" | |
44 | #include "wx/msw/mslu.h" | |
45 | ||
46 | #include <stdio.h> | |
47 | #include <io.h> | |
b36de7d0 | 48 | #include <sys/stat.h> |
136cb3c7 | 49 | |
d9628647 VS |
50 | #ifdef __VISUALC__ |
51 | #include <direct.h> | |
52 | #endif | |
136cb3c7 VS |
53 | |
54 | // Undef redirection macros defined in wx/msw/mslu.h: | |
55 | #undef DrawStateW | |
56 | #undef GetOpenFileNameW | |
57 | #undef GetSaveFileNameW | |
58 | ||
59 | //------------------------------------------------------------------------ | |
60 | // Wrongly implemented functions from unicows.dll | |
61 | //------------------------------------------------------------------------ | |
62 | ||
63 | #if wxUSE_GUI | |
64 | ||
2679196c RD |
65 | WXDLLEXPORT int wxMSLU_DrawStateW(WXHDC dc, WXHBRUSH br, WXFARPROC outputFunc, |
66 | WXLPARAM lData, WXWPARAM wData, | |
67 | int x, int y, int cx, int cy, | |
68 | unsigned int flags) | |
136cb3c7 VS |
69 | { |
70 | // VS: There's yet another bug in MSLU: DrawStateW behaves like if it was | |
b36de7d0 | 71 | // expecting char*, not wchar_t* input. We have to use DrawStateA |
136cb3c7 VS |
72 | // explicitly. |
73 | ||
74 | if ( wxUsingUnicowsDll() ) | |
75 | { | |
2b5f62a0 | 76 | return DrawStateA((HDC)dc, (HBRUSH)br, (DRAWSTATEPROC)outputFunc, |
136cb3c7 VS |
77 | (LPARAM)(const char*) |
78 | wxConvLocal.cWX2MB((const wxChar*)lData), | |
79 | wData, x, y, cx, cy, flags); | |
80 | } | |
81 | else | |
82 | { | |
b36de7d0 | 83 | return DrawStateW((HDC)dc, (HBRUSH)br, (DRAWSTATEPROC)outputFunc, |
136cb3c7 VS |
84 | lData, wData, x, y, cx, cy, flags); |
85 | } | |
86 | } | |
87 | ||
88 | static void wxFixOPENFILENAME(LPOPENFILENAME ofn) | |
89 | { | |
90 | #ifdef OFN_EXPLORER | |
b36de7d0 RD |
91 | // VS: there's a bug in unicows.dll - when multiple files are selected, |
92 | // of.nFileOffset doesn't point to the first filename but rather to | |
136cb3c7 | 93 | // the last component of directory name. This bug is known to MSLU |
b36de7d0 | 94 | // developers, but they are not going to fix it: "this is a true |
136cb3c7 VS |
95 | // limitation, that we have decided to live with" and "working |
96 | // harder on this case just did not seem worth the effort"... | |
97 | // | |
98 | // Our only option is to try to fix it ourselves: | |
99 | ||
100 | if ( (ofn->Flags & OFN_ALLOWMULTISELECT) && | |
101 | ofn->lpstrFile[ofn->nFileOffset-1] != wxT('\0') ) | |
102 | { | |
103 | if ( wxDirExists(ofn->lpstrFile) ) | |
104 | { | |
105 | // 1st component is dir => multiple files selected | |
106 | ofn->nFileOffset = wxStrlen(ofn->lpstrFile)+1; | |
107 | } | |
108 | } | |
109 | #endif | |
110 | } | |
111 | ||
2679196c | 112 | WXDLLEXPORT int wxMSLU_GetOpenFileNameW(void *ofn) |
136cb3c7 | 113 | { |
d9628647 | 114 | int ret = GetOpenFileName((LPOPENFILENAME)ofn); |
136cb3c7 VS |
115 | if ( wxUsingUnicowsDll() && ret != 0 ) |
116 | wxFixOPENFILENAME((LPOPENFILENAME)ofn); | |
117 | return ret; | |
118 | } | |
119 | ||
2679196c | 120 | WXDLLEXPORT int wxMSLU_GetSaveFileNameW(void *ofn) |
136cb3c7 | 121 | { |
d9628647 | 122 | int ret = GetSaveFileName((LPOPENFILENAME)ofn); |
136cb3c7 VS |
123 | if ( wxUsingUnicowsDll() && ret != 0 ) |
124 | wxFixOPENFILENAME((LPOPENFILENAME)ofn); | |
125 | return ret; | |
126 | } | |
127 | ||
128 | #endif // wxUSE_GUI | |
129 | ||
130 | //------------------------------------------------------------------------ | |
131 | // Missing libc file manipulation functions in Win9x | |
132 | //------------------------------------------------------------------------ | |
133 | ||
ec67cff1 | 134 | #if wxUSE_BASE |
e2478fde | 135 | |
450d55ba VS |
136 | WXDLLIMPEXP_BASE int wxMSLU__trename(const wxChar *oldname, |
137 | const wxChar *newname) | |
136cb3c7 VS |
138 | { |
139 | if ( wxUsingUnicowsDll() ) | |
140 | return rename(wxConvFile.cWX2MB(oldname), wxConvFile.cWX2MB(newname)); | |
141 | else | |
142 | return _trename(oldname, newname); | |
143 | } | |
144 | ||
450d55ba | 145 | WXDLLIMPEXP_BASE int wxMSLU__tremove(const wxChar *name) |
136cb3c7 VS |
146 | { |
147 | if ( wxUsingUnicowsDll() ) | |
148 | return remove(wxConvFile.cWX2MB(name)); | |
149 | else | |
150 | return _tremove(name); | |
151 | } | |
152 | ||
153 | #if defined( __VISUALC__ ) \ | |
154 | || ( defined(__MINGW32__) && wxCHECK_W32API_VERSION( 0, 5 ) ) \ | |
a3bb1d14 CE |
155 | || ( defined(__MWERKS__) && defined(__WXMSW__) ) \ |
156 | || ( defined(__BORLANDC__) && (__BORLANDC__ > 0x460) ) | |
136cb3c7 | 157 | |
450d55ba | 158 | WXDLLIMPEXP_BASE int wxMSLU__wopen(const wxChar *name, int flags, int mode) |
136cb3c7 VS |
159 | { |
160 | if ( wxUsingUnicowsDll() ) | |
a3bb1d14 CE |
161 | #ifdef __BORLANDC__ |
162 | return open(wxConvFile.cWX2MB(name), flags, mode); | |
163 | #else | |
136cb3c7 | 164 | return _open(wxConvFile.cWX2MB(name), flags, mode); |
a3bb1d14 | 165 | #endif |
136cb3c7 VS |
166 | else |
167 | return _wopen(name, flags, mode); | |
168 | } | |
169 | ||
450d55ba | 170 | WXDLLIMPEXP_BASE int wxMSLU__waccess(const wxChar *name, int mode) |
136cb3c7 VS |
171 | { |
172 | if ( wxUsingUnicowsDll() ) | |
173 | return _access(wxConvFile.cWX2MB(name), mode); | |
174 | else | |
175 | return _waccess(name, mode); | |
176 | } | |
177 | ||
450d55ba | 178 | WXDLLIMPEXP_BASE int wxMSLU__wmkdir(const wxChar *name) |
136cb3c7 VS |
179 | { |
180 | if ( wxUsingUnicowsDll() ) | |
181 | return _mkdir(wxConvFile.cWX2MB(name)); | |
182 | else | |
183 | return _wmkdir(name); | |
184 | } | |
185 | ||
450d55ba | 186 | WXDLLIMPEXP_BASE int wxMSLU__wrmdir(const wxChar *name) |
136cb3c7 VS |
187 | { |
188 | if ( wxUsingUnicowsDll() ) | |
189 | return _rmdir(wxConvFile.cWX2MB(name)); | |
190 | else | |
191 | return _wrmdir(name); | |
192 | } | |
193 | ||
450d55ba | 194 | WXDLLIMPEXP_BASE int wxMSLU__wstat(const wxChar *name, struct _stat *buffer) |
136cb3c7 VS |
195 | { |
196 | if ( wxUsingUnicowsDll() ) | |
197 | return _stat((const char*)wxConvFile.cWX2MB(name), buffer); | |
198 | else | |
199 | return _wstat(name, buffer); | |
200 | } | |
201 | ||
e2478fde VZ |
202 | #endif // compilers having wopen() &c |
203 | ||
ec67cff1 | 204 | #endif // wxUSE_BASE |
136cb3c7 VS |
205 | |
206 | #endif // wxUSE_UNICODE_MSLU |