]>
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 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #if wxUSE_UNICODE_MSLU
29 //------------------------------------------------------------------------
31 // NB: MSLU only covers Win32 API, it doesn't provide Unicode implementation of
32 // libc functions. Unfortunately, some of MSVCRT wchar_t functions
33 // (e.g. _wopen) don't work on Windows 9x, so we have to workaround it
34 // by calling the char version. We still want to use wchar_t version on
35 // NT/2000/XP, though, because they allow for Unicode file names.
37 // Moreover, there are bugs in unicows.dll, of course. We have to
38 // workaround them, too.
40 //------------------------------------------------------------------------
42 #include "wx/msw/private.h"
43 #include "wx/msw/mslu.h"
54 // Undef redirection macros defined in wx/msw/mslu.h:
56 #undef GetOpenFileNameW
57 #undef GetSaveFileNameW
59 //------------------------------------------------------------------------
60 // Wrongly implemented functions from unicows.dll
61 //------------------------------------------------------------------------
65 WXDLLEXPORT
bool wxMSLU_DrawStateW(WXHDC dc
, WXHBRUSH br
, WXFARPROC outputFunc
,
66 WXLPARAM lData
, WXWPARAM wData
,
67 int x
, int y
, int cx
, int cy
,
70 // VS: There's yet another bug in MSLU: DrawStateW behaves like if it was
71 // expecting char*, not wchar_t* input. We have to use DrawStateA
74 if ( wxUsingUnicowsDll() )
76 return DrawStateA((HDC
)dc
, (HBRUSH
)br
, (DRAWSTATEPROC
)outputFunc
,
78 wxConvLocal
.cWX2MB((const wxChar
*)lData
),
79 wData
, x
, y
, cx
, cy
, flags
);
83 return DrawStateW((HDC
)dc
, (HBRUSH
)br
, (DRAWSTATEPROC
)outputFunc
,
84 lData
, wData
, x
, y
, cx
, cy
, flags
);
88 static void wxFixOPENFILENAME(LPOPENFILENAME ofn
)
91 // VS: there's a bug in unicows.dll - when multiple files are selected,
92 // of.nFileOffset doesn't point to the first filename but rather to
93 // the last component of directory name. This bug is known to MSLU
94 // developers, but they are not going to fix it: "this is a true
95 // limitation, that we have decided to live with" and "working
96 // harder on this case just did not seem worth the effort"...
98 // Our only option is to try to fix it ourselves:
100 if ( (ofn
->Flags
& OFN_ALLOWMULTISELECT
) &&
101 ofn
->lpstrFile
[ofn
->nFileOffset
-1] != wxT('\0') )
103 if ( wxDirExists(ofn
->lpstrFile
) )
105 // 1st component is dir => multiple files selected
106 ofn
->nFileOffset
= wxStrlen(ofn
->lpstrFile
)+1;
112 WXDLLEXPORT
bool wxMSLU_GetOpenFileNameW(void *ofn
)
114 bool ret
= GetOpenFileName((LPOPENFILENAME
)ofn
);
115 if ( wxUsingUnicowsDll() && ret
!= 0 )
116 wxFixOPENFILENAME((LPOPENFILENAME
)ofn
);
120 WXDLLEXPORT
bool wxMSLU_GetSaveFileNameW(void *ofn
)
122 bool ret
= GetSaveFileName((LPOPENFILENAME
)ofn
);
123 if ( wxUsingUnicowsDll() && ret
!= 0 )
124 wxFixOPENFILENAME((LPOPENFILENAME
)ofn
);
130 //------------------------------------------------------------------------
131 // Missing libc file manipulation functions in Win9x
132 //------------------------------------------------------------------------
134 WXDLLEXPORT
int wxMSLU__trename(const wxChar
*oldname
, const wxChar
*newname
)
136 if ( wxUsingUnicowsDll() )
137 return rename(wxConvFile
.cWX2MB(oldname
), wxConvFile
.cWX2MB(newname
));
139 return _trename(oldname
, newname
);
142 WXDLLEXPORT
int wxMSLU__tremove(const wxChar
*name
)
144 if ( wxUsingUnicowsDll() )
145 return remove(wxConvFile
.cWX2MB(name
));
147 return _tremove(name
);
150 #if defined( __VISUALC__ ) \
151 || ( defined(__MINGW32__) && wxCHECK_W32API_VERSION( 0, 5 ) ) \
152 || ( defined(__MWERKS__) && defined(__WXMSW__) )
154 WXDLLEXPORT
int wxMSLU__wopen(const wxChar
*name
, int flags
, int mode
)
156 if ( wxUsingUnicowsDll() )
157 return _open(wxConvFile
.cWX2MB(name
), flags
, mode
);
159 return _wopen(name
, flags
, mode
);
162 WXDLLEXPORT
int wxMSLU__waccess(const wxChar
*name
, int mode
)
164 if ( wxUsingUnicowsDll() )
165 return _access(wxConvFile
.cWX2MB(name
), mode
);
167 return _waccess(name
, mode
);
170 WXDLLEXPORT
int wxMSLU__wmkdir(const wxChar
*name
)
172 if ( wxUsingUnicowsDll() )
173 return _mkdir(wxConvFile
.cWX2MB(name
));
175 return _wmkdir(name
);
178 WXDLLEXPORT
int wxMSLU__wrmdir(const wxChar
*name
)
180 if ( wxUsingUnicowsDll() )
181 return _rmdir(wxConvFile
.cWX2MB(name
));
183 return _wrmdir(name
);
186 WXDLLEXPORT
int wxMSLU__wstat(const wxChar
*name
, struct _stat
*buffer
)
188 if ( wxUsingUnicowsDll() )
189 return _stat((const char*)wxConvFile
.cWX2MB(name
), buffer
);
191 return _wstat(name
, buffer
);
196 #endif // wxUSE_UNICODE_MSLU