]>
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 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
25 //------------------------------------------------------------------------
26 // Check for use of MSLU
27 //------------------------------------------------------------------------
31 bool WXDLLIMPEXP_BASE
wxUsingUnicowsDll()
33 #if wxUSE_UNICODE_MSLU
34 return (wxGetOsVersion() == wxWIN95
);
43 #if wxUSE_UNICODE_MSLU
45 //------------------------------------------------------------------------
47 // NB: MSLU only covers Win32 API, it doesn't provide Unicode implementation of
48 // libc functions. Unfortunately, some of MSVCRT wchar_t functions
49 // (e.g. _wopen) don't work on Windows 9x, so we have to workaround it
50 // by calling the char version. We still want to use wchar_t version on
51 // NT/2000/XP, though, because they allow for Unicode file names.
53 // Moreover, there are bugs in unicows.dll, of course. We have to
54 // workaround them, too.
56 //------------------------------------------------------------------------
58 #include "wx/msw/private.h"
59 #include "wx/msw/mslu.h"
69 // Undef redirection macros defined in wx/msw/mslu.h:
71 #undef GetOpenFileNameW
72 #undef GetSaveFileNameW
74 //------------------------------------------------------------------------
75 // Wrongly implemented functions from unicows.dll
76 //------------------------------------------------------------------------
80 WXDLLEXPORT
int wxMSLU_DrawStateW(WXHDC dc
, WXHBRUSH br
, WXFARPROC outputFunc
,
81 WXLPARAM lData
, WXWPARAM wData
,
82 int x
, int y
, int cx
, int cy
,
85 // VS: There's yet another bug in MSLU: DrawStateW behaves like if it was
86 // expecting char*, not wchar_t* input. We have to use DrawStateA
89 if ( wxUsingUnicowsDll() )
91 return DrawStateA((HDC
)dc
, (HBRUSH
)br
, (DRAWSTATEPROC
)outputFunc
,
93 wxConvLocal
.cWX2MB((const wxChar
*)lData
),
94 wData
, x
, y
, cx
, cy
, flags
);
98 return DrawStateW((HDC
)dc
, (HBRUSH
)br
, (DRAWSTATEPROC
)outputFunc
,
99 lData
, wData
, x
, y
, cx
, cy
, flags
);
103 static void wxFixOPENFILENAME(LPOPENFILENAME ofn
)
106 // VS: there's a bug in unicows.dll - when multiple files are selected,
107 // of.nFileOffset doesn't point to the first filename but rather to
108 // the last component of directory name. This bug is known to MSLU
109 // developers, but they are not going to fix it: "this is a true
110 // limitation, that we have decided to live with" and "working
111 // harder on this case just did not seem worth the effort"...
113 // Our only option is to try to fix it ourselves:
115 if ( (ofn
->Flags
& OFN_ALLOWMULTISELECT
) &&
116 ofn
->lpstrFile
[ofn
->nFileOffset
-1] != wxT('\0') )
118 if ( wxDirExists(ofn
->lpstrFile
) )
120 // 1st component is dir => multiple files selected
121 ofn
->nFileOffset
= wxStrlen(ofn
->lpstrFile
)+1;
127 WXDLLEXPORT
int wxMSLU_GetOpenFileNameW(void *ofn
)
129 int ret
= GetOpenFileName((LPOPENFILENAME
)ofn
);
130 if ( wxUsingUnicowsDll() && ret
!= 0 )
131 wxFixOPENFILENAME((LPOPENFILENAME
)ofn
);
135 WXDLLEXPORT
int wxMSLU_GetSaveFileNameW(void *ofn
)
137 int ret
= GetSaveFileName((LPOPENFILENAME
)ofn
);
138 if ( wxUsingUnicowsDll() && ret
!= 0 )
139 wxFixOPENFILENAME((LPOPENFILENAME
)ofn
);
145 //------------------------------------------------------------------------
146 // Missing libc file manipulation functions in Win9x
147 //------------------------------------------------------------------------
151 WXDLLIMPEXP_BASE
int wxMSLU__trename(const wxChar
*oldname
,
152 const wxChar
*newname
)
154 if ( wxUsingUnicowsDll() )
155 return rename(wxConvFile
.cWX2MB(oldname
), wxConvFile
.cWX2MB(newname
));
157 return _trename(oldname
, newname
);
160 WXDLLIMPEXP_BASE
int wxMSLU__tremove(const wxChar
*name
)
162 if ( wxUsingUnicowsDll() )
163 return remove(wxConvFile
.cWX2MB(name
));
165 return _tremove(name
);
168 WXDLLIMPEXP_BASE
FILE* wxMSLU__tfopen(const wxChar
*name
,const wxChar
* mode
)
170 if ( wxUsingUnicowsDll() )
171 return fopen(wxConvFile
.cWX2MB(name
),wxConvFile
.cWX2MB(mode
));
173 return _tfopen(name
,mode
);
176 #if defined( __VISUALC__ ) \
177 || ( defined(__MINGW32__) && wxCHECK_W32API_VERSION( 0, 5 ) ) \
178 || ( defined(__MWERKS__) && defined(__WXMSW__) ) \
179 || ( defined(__BORLANDC__) && (__BORLANDC__ > 0x460) )
181 WXDLLIMPEXP_BASE
int wxMSLU__wopen(const wxChar
*name
, int flags
, int mode
)
183 if ( wxUsingUnicowsDll() )
185 return open(wxConvFile
.cWX2MB(name
), flags
, mode
);
187 return _open(wxConvFile
.cWX2MB(name
), flags
, mode
);
190 return _wopen(name
, flags
, mode
);
193 WXDLLIMPEXP_BASE
int wxMSLU__waccess(const wxChar
*name
, int mode
)
195 if ( wxUsingUnicowsDll() )
196 return _access(wxConvFile
.cWX2MB(name
), mode
);
198 return _waccess(name
, mode
);
201 WXDLLIMPEXP_BASE
int wxMSLU__wmkdir(const wxChar
*name
)
203 if ( wxUsingUnicowsDll() )
204 return _mkdir(wxConvFile
.cWX2MB(name
));
206 return _wmkdir(name
);
209 WXDLLIMPEXP_BASE
int wxMSLU__wrmdir(const wxChar
*name
)
211 if ( wxUsingUnicowsDll() )
212 return _rmdir(wxConvFile
.cWX2MB(name
));
214 return _wrmdir(name
);
217 WXDLLIMPEXP_BASE
int wxMSLU__wstat(const wxChar
*name
, struct _stat
*buffer
)
219 if ( wxUsingUnicowsDll() )
220 return _stat((const char*)wxConvFile
.cWX2MB(name
), buffer
);
222 return _wstat(name
, buffer
);
225 WXDLLIMPEXP_BASE
int wxMSLU__wstati64(const wxChar
*name
, struct _stati64
*buffer
)
227 if ( wxUsingUnicowsDll() )
228 return _stati64((const char*)wxConvFile
.cWX2MB(name
), buffer
);
230 return _wstati64(name
, buffer
);
233 #endif // compilers having wopen() &c
237 #endif // wxUSE_UNICODE_MSLU