]>
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 #define wxHAS_HUGE_FILES
26 //------------------------------------------------------------------------
27 // Check for use of MSLU
28 //------------------------------------------------------------------------
32 bool WXDLLIMPEXP_BASE
wxUsingUnicowsDll()
34 #if wxUSE_UNICODE_MSLU
35 return (wxGetOsVersion() == wxOS_WINDOWS_9X
);
44 #if wxUSE_UNICODE_MSLU
46 //------------------------------------------------------------------------
48 // NB: MSLU only covers Win32 API, it doesn't provide Unicode implementation of
49 // libc functions. Unfortunately, some of MSVCRT wchar_t functions
50 // (e.g. _wopen) don't work on Windows 9x, so we have to workaround it
51 // by calling the char version. We still want to use wchar_t version on
52 // NT/2000/XP, though, because they allow for Unicode file names.
54 // Moreover, there are bugs in unicows.dll, of course. We have to
55 // workaround them, too.
57 //------------------------------------------------------------------------
59 #include "wx/msw/private.h"
60 #include "wx/msw/mslu.h"
70 // Undef redirection macros defined in wx/msw/wrapwin.h:
72 #undef GetOpenFileNameW
73 #undef GetSaveFileNameW
75 //------------------------------------------------------------------------
76 // Wrongly implemented functions from unicows.dll
77 //------------------------------------------------------------------------
81 WXDLLEXPORT
int wxMSLU_DrawStateW(WXHDC dc
, WXHBRUSH br
, WXFARPROC outputFunc
,
82 WXLPARAM lData
, WXWPARAM wData
,
83 int x
, int y
, int cx
, int cy
,
86 // VS: There's yet another bug in MSLU: DrawStateW behaves like if it was
87 // expecting char*, not wchar_t* input. We have to use DrawStateA
90 if ( wxUsingUnicowsDll() )
92 return DrawStateA((HDC
)dc
, (HBRUSH
)br
, (DRAWSTATEPROC
)outputFunc
,
94 wxConvLocal
.cWX2MB((const wxChar
*)lData
),
95 wData
, x
, y
, cx
, cy
, flags
);
99 return DrawStateW((HDC
)dc
, (HBRUSH
)br
, (DRAWSTATEPROC
)outputFunc
,
100 lData
, wData
, x
, y
, cx
, cy
, flags
);
104 static void wxFixOPENFILENAME(LPOPENFILENAME ofn
)
107 // VS: there's a bug in unicows.dll - when multiple files are selected,
108 // of.nFileOffset doesn't point to the first filename but rather to
109 // the last component of directory name. This bug is known to MSLU
110 // developers, but they are not going to fix it: "this is a true
111 // limitation, that we have decided to live with" and "working
112 // harder on this case just did not seem worth the effort"...
114 // Our only option is to try to fix it ourselves:
116 if ( (ofn
->Flags
& OFN_ALLOWMULTISELECT
) &&
117 ofn
->lpstrFile
[ofn
->nFileOffset
-1] != wxT('\0') )
119 if ( wxDirExists(ofn
->lpstrFile
) )
121 // 1st component is dir => multiple files selected
122 ofn
->nFileOffset
= wxStrlen(ofn
->lpstrFile
)+1;
125 #endif // OFN_EXPLORER
128 WXDLLEXPORT
int wxMSLU_GetOpenFileNameW(void *ofn
)
130 int ret
= GetOpenFileName((LPOPENFILENAME
)ofn
);
131 if ( wxUsingUnicowsDll() && ret
!= 0 )
132 wxFixOPENFILENAME((LPOPENFILENAME
)ofn
);
136 WXDLLEXPORT
int wxMSLU_GetSaveFileNameW(void *ofn
)
138 int ret
= GetSaveFileName((LPOPENFILENAME
)ofn
);
139 if ( wxUsingUnicowsDll() && ret
!= 0 )
140 wxFixOPENFILENAME((LPOPENFILENAME
)ofn
);
146 //------------------------------------------------------------------------
147 // Missing libc file manipulation functions in Win9x
148 //------------------------------------------------------------------------
152 WXDLLIMPEXP_BASE
int wxMSLU__wrename(const wchar_t *oldname
,
153 const wchar_t *newname
)
155 if ( wxUsingUnicowsDll() )
156 return rename(wxConvFile
.cWX2MB(oldname
), wxConvFile
.cWX2MB(newname
));
158 return _wrename(oldname
, newname
);
161 WXDLLIMPEXP_BASE
int wxMSLU__wremove(const wchar_t *name
)
163 if ( wxUsingUnicowsDll() )
164 return remove(wxConvFile
.cWX2MB(name
));
166 return _wremove(name
);
169 WXDLLIMPEXP_BASE
FILE* wxMSLU__wfopen(const wchar_t *name
,const wchar_t* mode
)
171 if ( wxUsingUnicowsDll() )
172 return fopen(wxConvFile
.cWX2MB(name
),wxConvFile
.cWX2MB(mode
));
174 return _wfopen(name
,mode
);
177 WXDLLIMPEXP_BASE
FILE* wxMSLU__wfreopen(const wchar_t *name
,
181 if ( wxUsingUnicowsDll() )
182 return freopen(wxConvFile
.cWX2MB(name
), wxConvFile
.cWX2MB(mode
), stream
);
184 return _wfreopen(name
, mode
, stream
);
187 WXDLLIMPEXP_BASE
int wxMSLU__wopen(const wchar_t *name
, int flags
, int mode
)
189 if ( wxUsingUnicowsDll() )
190 return wxCRT_OpenA(wxConvFile
.cWX2MB(name
), flags
, mode
);
192 return wxCRT_OpenW(name
, flags
, mode
);
195 WXDLLIMPEXP_BASE
int wxMSLU__waccess(const wchar_t *name
, int mode
)
197 if ( wxUsingUnicowsDll() )
198 return wxCRT_AccessA(wxConvFile
.cWX2MB(name
), mode
);
200 return wxCRT_AccessW(name
, mode
);
203 WXDLLIMPEXP_BASE
int wxMSLU__wmkdir(const wchar_t *name
)
205 if ( wxUsingUnicowsDll() )
206 return wxCRT_MkDirA(wxConvFile
.cWX2MB(name
));
208 return wxCRT_MkDirW(name
);
211 WXDLLIMPEXP_BASE
int wxMSLU__wrmdir(const wchar_t *name
)
213 if ( wxUsingUnicowsDll() )
214 return wxCRT_RmDirA(wxConvFile
.cWX2MB(name
));
216 return wxCRT_RmDirW(name
);
219 WXDLLIMPEXP_BASE
int wxMSLU__wstat(const wchar_t *name
, wxStructStat
*buffer
)
221 if ( wxUsingUnicowsDll() )
222 return wxCRT_StatA((const char*)wxConvFile
.cWX2MB(name
), buffer
);
224 return wxCRT_StatW(name
, buffer
);
229 #endif // wxUSE_UNICODE_MSLU