]>
git.saurik.com Git - wxWidgets.git/blob - src/palmos/mslu.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Fixes for bugs in MSLU
4 // Author: Vaclav Slavik
8 // Copyright: (c) 2002 Vaclav Slavik
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
19 // This may or may not apply to Palm OS in the future, but for right now Unicode
32 #if wxUSE_UNICODE_MSLU
34 //------------------------------------------------------------------------
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.
42 // Moreover, there are bugs in unicows.dll, of course. We have to
43 // workaround them, too.
45 //------------------------------------------------------------------------
47 #include "wx/msw/private.h"
48 #include "wx/msw/mslu.h"
58 // Undef redirection macros defined in wx/msw/mslu.h:
60 #undef GetOpenFileNameW
61 #undef GetSaveFileNameW
63 //------------------------------------------------------------------------
64 // Wrongly implemented functions from unicows.dll
65 //------------------------------------------------------------------------
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
,
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
78 if ( wxUsingUnicowsDll() )
80 return DrawStateA((HDC
)dc
, (HBRUSH
)br
, (DRAWSTATEPROC
)outputFunc
,
82 wxConvLocal
.cWX2MB((const wxChar
*)lData
),
83 wData
, x
, y
, cx
, cy
, flags
);
87 return DrawStateW((HDC
)dc
, (HBRUSH
)br
, (DRAWSTATEPROC
)outputFunc
,
88 lData
, wData
, x
, y
, cx
, cy
, flags
);
92 static void wxFixOPENFILENAME(LPOPENFILENAME ofn
)
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"...
102 // Our only option is to try to fix it ourselves:
104 if ( (ofn
->Flags
& OFN_ALLOWMULTISELECT
) &&
105 ofn
->lpstrFile
[ofn
->nFileOffset
-1] != wxT('\0') )
107 if ( wxDirExists(ofn
->lpstrFile
) )
109 // 1st component is dir => multiple files selected
110 ofn
->nFileOffset
= wxStrlen(ofn
->lpstrFile
)+1;
116 WXDLLEXPORT
int wxMSLU_GetOpenFileNameW(void *ofn
)
118 int ret
= GetOpenFileName((LPOPENFILENAME
)ofn
);
119 if ( wxUsingUnicowsDll() && ret
!= 0 )
120 wxFixOPENFILENAME((LPOPENFILENAME
)ofn
);
124 WXDLLEXPORT
int wxMSLU_GetSaveFileNameW(void *ofn
)
126 int ret
= GetSaveFileName((LPOPENFILENAME
)ofn
);
127 if ( wxUsingUnicowsDll() && ret
!= 0 )
128 wxFixOPENFILENAME((LPOPENFILENAME
)ofn
);
134 //------------------------------------------------------------------------
135 // Missing libc file manipulation functions in Win9x
136 //------------------------------------------------------------------------
140 WXDLLEXPORT
int wxMSLU__trename(const wxChar
*oldname
, const wxChar
*newname
)
142 if ( wxUsingUnicowsDll() )
143 return rename(wxConvFile
.cWX2MB(oldname
), wxConvFile
.cWX2MB(newname
));
145 return _trename(oldname
, newname
);
148 WXDLLEXPORT
int wxMSLU__tremove(const wxChar
*name
)
150 if ( wxUsingUnicowsDll() )
151 return remove(wxConvFile
.cWX2MB(name
));
153 return _tremove(name
);
156 #if defined( __VISUALC__ ) \
157 || ( defined(__MINGW32__) && wxCHECK_W32API_VERSION( 0, 5 ) ) \
158 || ( defined(__MWERKS__) && defined(__WXMSW__) ) \
159 || ( defined(__BORLANDC__) && (__BORLANDC__ > 0x460) )
161 WXDLLEXPORT
int wxMSLU__wopen(const wxChar
*name
, int flags
, int mode
)
163 if ( wxUsingUnicowsDll() )
165 return open(wxConvFile
.cWX2MB(name
), flags
, mode
);
167 return _open(wxConvFile
.cWX2MB(name
), flags
, mode
);
170 return _wopen(name
, flags
, mode
);
173 WXDLLEXPORT
int wxMSLU__waccess(const wxChar
*name
, int mode
)
175 if ( wxUsingUnicowsDll() )
176 return _access(wxConvFile
.cWX2MB(name
), mode
);
178 return _waccess(name
, mode
);
181 WXDLLEXPORT
int wxMSLU__wmkdir(const wxChar
*name
)
183 if ( wxUsingUnicowsDll() )
184 return _mkdir(wxConvFile
.cWX2MB(name
));
186 return _wmkdir(name
);
189 WXDLLEXPORT
int wxMSLU__wrmdir(const wxChar
*name
)
191 if ( wxUsingUnicowsDll() )
192 return _rmdir(wxConvFile
.cWX2MB(name
));
194 return _wrmdir(name
);
197 WXDLLEXPORT
int wxMSLU__wstat(const wxChar
*name
, struct _stat
*buffer
)
199 if ( wxUsingUnicowsDll() )
200 return _stat((const char*)wxConvFile
.cWX2MB(name
), buffer
);
202 return _wstat(name
, buffer
);
205 #endif // compilers having wopen() &c
209 #endif // wxUSE_UNICODE_MSLU