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