]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/mslu.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/mslu.cpp
3 // Purpose: Fixes for bugs in MSLU
4 // Author: Vaclav Slavik
8 // Copyright: (c) 2002 Vaclav Slavik
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
24 //------------------------------------------------------------------------
25 // Check for use of MSLU
26 //------------------------------------------------------------------------
30 bool WXDLLIMPEXP_BASE
wxUsingUnicowsDll()
32 #if wxUSE_UNICODE_MSLU
33 return (wxGetOsVersion() == wxOS_WINDOWS_9X
);
42 #if wxUSE_UNICODE_MSLU
44 //------------------------------------------------------------------------
46 // NB: MSLU only covers Win32 API, it doesn't provide Unicode implementation of
47 // libc functions. Unfortunately, some of MSVCRT wchar_t functions
48 // (e.g. _wopen) don't work on Windows 9x, so we have to workaround it
49 // by calling the char version. We still want to use wchar_t version on
50 // NT/2000/XP, though, because they allow for Unicode file names.
52 // Moreover, there are bugs in unicows.dll, of course. We have to
53 // workaround them, too.
55 //------------------------------------------------------------------------
57 #include "wx/msw/private.h"
58 #include "wx/msw/mslu.h"
68 // Undef redirection macros defined in wx/msw/wrapwin.h:
70 #undef GetOpenFileNameW
71 #undef GetSaveFileNameW
73 //------------------------------------------------------------------------
74 // Wrongly implemented functions from unicows.dll
75 //------------------------------------------------------------------------
79 WXDLLEXPORT
int wxMSLU_DrawStateW(WXHDC dc
, WXHBRUSH br
, WXFARPROC outputFunc
,
80 WXLPARAM lData
, WXWPARAM wData
,
81 int x
, int y
, int cx
, int cy
,
84 // VS: There's yet another bug in MSLU: DrawStateW behaves like if it was
85 // expecting char*, not wchar_t* input. We have to use DrawStateA
88 if ( wxUsingUnicowsDll() )
90 return DrawStateA((HDC
)dc
, (HBRUSH
)br
, (DRAWSTATEPROC
)outputFunc
,
92 wxConvLocal
.cWX2MB((const wxChar
*)lData
),
93 wData
, x
, y
, cx
, cy
, flags
);
97 return DrawStateW((HDC
)dc
, (HBRUSH
)br
, (DRAWSTATEPROC
)outputFunc
,
98 lData
, wData
, x
, y
, cx
, cy
, flags
);
102 static void wxFixOPENFILENAME(LPOPENFILENAME ofn
)
105 // VS: there's a bug in unicows.dll - when multiple files are selected,
106 // of.nFileOffset doesn't point to the first filename but rather to
107 // the last component of directory name. This bug is known to MSLU
108 // developers, but they are not going to fix it: "this is a true
109 // limitation, that we have decided to live with" and "working
110 // harder on this case just did not seem worth the effort"...
112 // Our only option is to try to fix it ourselves:
114 if ( (ofn
->Flags
& OFN_ALLOWMULTISELECT
) &&
115 ofn
->lpstrFile
[ofn
->nFileOffset
-1] != wxT('\0') )
117 if ( wxDirExists(ofn
->lpstrFile
) )
119 // 1st component is dir => multiple files selected
120 ofn
->nFileOffset
= wxStrlen(ofn
->lpstrFile
)+1;
123 #endif // OFN_EXPLORER
126 WXDLLEXPORT
int wxMSLU_GetOpenFileNameW(void *ofn
)
128 int ret
= GetOpenFileName((LPOPENFILENAME
)ofn
);
129 if ( wxUsingUnicowsDll() && ret
!= 0 )
130 wxFixOPENFILENAME((LPOPENFILENAME
)ofn
);
134 WXDLLEXPORT
int wxMSLU_GetSaveFileNameW(void *ofn
)
136 int ret
= GetSaveFileName((LPOPENFILENAME
)ofn
);
137 if ( wxUsingUnicowsDll() && ret
!= 0 )
138 wxFixOPENFILENAME((LPOPENFILENAME
)ofn
);
144 //------------------------------------------------------------------------
145 // Missing libc file manipulation functions in Win9x
146 //------------------------------------------------------------------------
150 WXDLLIMPEXP_BASE
int wxMSLU__wrename(const wchar_t *oldname
,
151 const wchar_t *newname
)
153 if ( wxUsingUnicowsDll() )
154 return rename(wxConvFile
.cWX2MB(oldname
), wxConvFile
.cWX2MB(newname
));
156 return _wrename(oldname
, newname
);
159 WXDLLIMPEXP_BASE
int wxMSLU__wremove(const wchar_t *name
)
161 if ( wxUsingUnicowsDll() )
162 return remove(wxConvFile
.cWX2MB(name
));
164 return _wremove(name
);
167 WXDLLIMPEXP_BASE
FILE* wxMSLU__wfopen(const wchar_t *name
,const wchar_t* mode
)
169 if ( wxUsingUnicowsDll() )
170 return fopen(wxConvFile
.cWX2MB(name
),wxConvFile
.cWX2MB(mode
));
172 return _wfopen(name
,mode
);
175 WXDLLIMPEXP_BASE
FILE* wxMSLU__wfreopen(const wchar_t *name
,
179 if ( wxUsingUnicowsDll() )
180 return freopen(wxConvFile
.cWX2MB(name
), wxConvFile
.cWX2MB(mode
), stream
);
182 return _wfreopen(name
, mode
, stream
);
185 #if defined( __VISUALC__ ) \
186 || ( defined(__MINGW32__) && wxCHECK_W32API_VERSION( 0, 5 ) ) \
187 || ( defined(__MWERKS__) && defined(__WXMSW__) ) \
188 || ( defined(__BORLANDC__) && (__BORLANDC__ > 0x460) )
190 WXDLLIMPEXP_BASE
int wxMSLU__wopen(const wchar_t *name
, int flags
, int mode
)
192 if ( wxUsingUnicowsDll() )
194 return open(wxConvFile
.cWX2MB(name
), flags
, mode
);
196 return _open(wxConvFile
.cWX2MB(name
), flags
, mode
);
199 return _wopen(name
, flags
, mode
);
202 WXDLLIMPEXP_BASE
int wxMSLU__waccess(const wchar_t *name
, int mode
)
204 if ( wxUsingUnicowsDll() )
205 return _access(wxConvFile
.cWX2MB(name
), mode
);
207 return _waccess(name
, mode
);
210 WXDLLIMPEXP_BASE
int wxMSLU__wmkdir(const wchar_t *name
)
212 if ( wxUsingUnicowsDll() )
213 return _mkdir(wxConvFile
.cWX2MB(name
));
215 return _wmkdir(name
);
218 WXDLLIMPEXP_BASE
int wxMSLU__wrmdir(const wchar_t *name
)
220 if ( wxUsingUnicowsDll() )
221 return _rmdir(wxConvFile
.cWX2MB(name
));
223 return _wrmdir(name
);
226 #ifdef wxHAS_HUGE_FILES
227 WXDLLIMPEXP_BASE
int wxMSLU__wstati64(const wchar_t *name
, wxStructStat
*buffer
)
229 if ( wxUsingUnicowsDll() )
230 return _stati64((const char*)wxConvFile
.cWX2MB(name
), buffer
);
232 return _wstati64(name
, buffer
);
234 #else // !wxHAS_HUGE_FILES
235 WXDLLIMPEXP_BASE
int wxMSLU__wstat(const wchar_t *name
, wxStructStat
*buffer
)
237 if ( wxUsingUnicowsDll() )
238 return _stat((const char*)wxConvFile
.cWX2MB(name
), buffer
);
240 return _wstat(name
, buffer
);
243 #endif // wxHAS_HUGE_FILES/!wxHAS_HUGE_FILES
245 #endif // compilers having wopen() &c
249 #endif // wxUSE_UNICODE_MSLU