]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/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"
28 //------------------------------------------------------------------------
29 // Check for use of MSLU
30 //------------------------------------------------------------------------
34 bool WXDLLIMPEXP_BASE
wxUsingUnicowsDll()
36 #if wxUSE_UNICODE_MSLU
37 return (wxGetOsVersion() == wxWIN95
);
46 #if wxUSE_UNICODE_MSLU
48 //------------------------------------------------------------------------
50 // NB: MSLU only covers Win32 API, it doesn't provide Unicode implementation of
51 // libc functions. Unfortunately, some of MSVCRT wchar_t functions
52 // (e.g. _wopen) don't work on Windows 9x, so we have to workaround it
53 // by calling the char version. We still want to use wchar_t version on
54 // NT/2000/XP, though, because they allow for Unicode file names.
56 // Moreover, there are bugs in unicows.dll, of course. We have to
57 // workaround them, too.
59 //------------------------------------------------------------------------
61 #include "wx/msw/private.h"
62 #include "wx/msw/mslu.h"
72 // Undef redirection macros defined in wx/msw/mslu.h:
74 #undef GetOpenFileNameW
75 #undef GetSaveFileNameW
77 //------------------------------------------------------------------------
78 // Wrongly implemented functions from unicows.dll
79 //------------------------------------------------------------------------
83 WXDLLEXPORT
int wxMSLU_DrawStateW(WXHDC dc
, WXHBRUSH br
, WXFARPROC outputFunc
,
84 WXLPARAM lData
, WXWPARAM wData
,
85 int x
, int y
, int cx
, int cy
,
88 // VS: There's yet another bug in MSLU: DrawStateW behaves like if it was
89 // expecting char*, not wchar_t* input. We have to use DrawStateA
92 if ( wxUsingUnicowsDll() )
94 return DrawStateA((HDC
)dc
, (HBRUSH
)br
, (DRAWSTATEPROC
)outputFunc
,
96 wxConvLocal
.cWX2MB((const wxChar
*)lData
),
97 wData
, x
, y
, cx
, cy
, flags
);
101 return DrawStateW((HDC
)dc
, (HBRUSH
)br
, (DRAWSTATEPROC
)outputFunc
,
102 lData
, wData
, x
, y
, cx
, cy
, flags
);
106 static void wxFixOPENFILENAME(LPOPENFILENAME ofn
)
109 // VS: there's a bug in unicows.dll - when multiple files are selected,
110 // of.nFileOffset doesn't point to the first filename but rather to
111 // the last component of directory name. This bug is known to MSLU
112 // developers, but they are not going to fix it: "this is a true
113 // limitation, that we have decided to live with" and "working
114 // harder on this case just did not seem worth the effort"...
116 // Our only option is to try to fix it ourselves:
118 if ( (ofn
->Flags
& OFN_ALLOWMULTISELECT
) &&
119 ofn
->lpstrFile
[ofn
->nFileOffset
-1] != wxT('\0') )
121 if ( wxDirExists(ofn
->lpstrFile
) )
123 // 1st component is dir => multiple files selected
124 ofn
->nFileOffset
= wxStrlen(ofn
->lpstrFile
)+1;
130 WXDLLEXPORT
int wxMSLU_GetOpenFileNameW(void *ofn
)
132 int ret
= GetOpenFileName((LPOPENFILENAME
)ofn
);
133 if ( wxUsingUnicowsDll() && ret
!= 0 )
134 wxFixOPENFILENAME((LPOPENFILENAME
)ofn
);
138 WXDLLEXPORT
int wxMSLU_GetSaveFileNameW(void *ofn
)
140 int ret
= GetSaveFileName((LPOPENFILENAME
)ofn
);
141 if ( wxUsingUnicowsDll() && ret
!= 0 )
142 wxFixOPENFILENAME((LPOPENFILENAME
)ofn
);
148 //------------------------------------------------------------------------
149 // Missing libc file manipulation functions in Win9x
150 //------------------------------------------------------------------------
154 WXDLLIMPEXP_BASE
int wxMSLU__trename(const wxChar
*oldname
,
155 const wxChar
*newname
)
157 if ( wxUsingUnicowsDll() )
158 return rename(wxConvFile
.cWX2MB(oldname
), wxConvFile
.cWX2MB(newname
));
160 return _trename(oldname
, newname
);
163 WXDLLIMPEXP_BASE
int wxMSLU__tremove(const wxChar
*name
)
165 if ( wxUsingUnicowsDll() )
166 return remove(wxConvFile
.cWX2MB(name
));
168 return _tremove(name
);
171 #if defined( __VISUALC__ ) \
172 || ( defined(__MINGW32__) && wxCHECK_W32API_VERSION( 0, 5 ) ) \
173 || ( defined(__MWERKS__) && defined(__WXMSW__) ) \
174 || ( defined(__BORLANDC__) && (__BORLANDC__ > 0x460) )
176 WXDLLIMPEXP_BASE
int wxMSLU__wopen(const wxChar
*name
, int flags
, int mode
)
178 if ( wxUsingUnicowsDll() )
180 return open(wxConvFile
.cWX2MB(name
), flags
, mode
);
182 return _open(wxConvFile
.cWX2MB(name
), flags
, mode
);
185 return _wopen(name
, flags
, mode
);
188 WXDLLIMPEXP_BASE
int wxMSLU__waccess(const wxChar
*name
, int mode
)
190 if ( wxUsingUnicowsDll() )
191 return _access(wxConvFile
.cWX2MB(name
), mode
);
193 return _waccess(name
, mode
);
196 WXDLLIMPEXP_BASE
int wxMSLU__wmkdir(const wxChar
*name
)
198 if ( wxUsingUnicowsDll() )
199 return _mkdir(wxConvFile
.cWX2MB(name
));
201 return _wmkdir(name
);
204 WXDLLIMPEXP_BASE
int wxMSLU__wrmdir(const wxChar
*name
)
206 if ( wxUsingUnicowsDll() )
207 return _rmdir(wxConvFile
.cWX2MB(name
));
209 return _wrmdir(name
);
212 WXDLLIMPEXP_BASE
int wxMSLU__wstat(const wxChar
*name
, struct _stat
*buffer
)
214 if ( wxUsingUnicowsDll() )
215 return _stat((const char*)wxConvFile
.cWX2MB(name
), buffer
);
217 return _wstat(name
, buffer
);
220 WXDLLIMPEXP_BASE
int wxMSLU__wstati64(const wxChar
*name
, struct _stati64
*buffer
)
222 if ( wxUsingUnicowsDll() )
223 return _stati64((const char*)wxConvFile
.cWX2MB(name
), buffer
);
225 return _wstati64(name
, buffer
);
228 #endif // compilers having wopen() &c
232 #endif // wxUSE_UNICODE_MSLU