]> git.saurik.com Git - wxWidgets.git/blame - src/msw/mslu.cpp
add accessors for sockaddr to wxSockAddress (closes #10511)
[wxWidgets.git] / src / msw / mslu.cpp
CommitLineData
136cb3c7 1/////////////////////////////////////////////////////////////////////////////
7520f3da 2// Name: src/msw/mslu.cpp
136cb3c7
VS
3// Purpose: Fixes for bugs in MSLU
4// Author: Vaclav Slavik
5// Modified by:
6// Created: 2002/02/17
7// RCS-ID: $Id$
8// Copyright: (c) 2002 Vaclav Slavik
65571936 9// Licence: wxWindows licence
136cb3c7
VS
10/////////////////////////////////////////////////////////////////////////////
11
136cb3c7
VS
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
7520f3da
WS
16 #pragma hdrstop
17 #include <dir.h>
136cb3c7
VS
18#endif
19
20#ifndef WX_PRECOMP
e11898f9 21 #include "wx/utils.h"
136cb3c7
VS
22#endif
23
b057f88a 24//------------------------------------------------------------------------
7eb872f4
VS
25// Check for use of MSLU
26//------------------------------------------------------------------------
27
28#if wxUSE_BASE
29
30bool WXDLLIMPEXP_BASE wxUsingUnicowsDll()
31{
32#if wxUSE_UNICODE_MSLU
406d283a 33 return (wxGetOsVersion() == wxOS_WINDOWS_9X);
7eb872f4
VS
34#else
35 return false;
36#endif
37}
38
39#endif // wxUSE_BASE
40
b057f88a 41
45f410f2 42#if wxUSE_UNICODE_MSLU
136cb3c7
VS
43
44//------------------------------------------------------------------------
45//
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.
51//
b36de7d0 52// Moreover, there are bugs in unicows.dll, of course. We have to
136cb3c7
VS
53// workaround them, too.
54//
55//------------------------------------------------------------------------
56
57#include "wx/msw/private.h"
58#include "wx/msw/mslu.h"
59
60#include <stdio.h>
61#include <io.h>
b36de7d0 62#include <sys/stat.h>
136cb3c7 63
d9628647
VS
64#ifdef __VISUALC__
65 #include <direct.h>
66#endif
136cb3c7 67
6dad7fff 68// Undef redirection macros defined in wx/msw/wrapwin.h:
136cb3c7
VS
69#undef DrawStateW
70#undef GetOpenFileNameW
71#undef GetSaveFileNameW
72
73//------------------------------------------------------------------------
74// Wrongly implemented functions from unicows.dll
75//------------------------------------------------------------------------
76
77#if wxUSE_GUI
78
2679196c
RD
79WXDLLEXPORT int wxMSLU_DrawStateW(WXHDC dc, WXHBRUSH br, WXFARPROC outputFunc,
80 WXLPARAM lData, WXWPARAM wData,
81 int x, int y, int cx, int cy,
82 unsigned int flags)
136cb3c7
VS
83{
84 // VS: There's yet another bug in MSLU: DrawStateW behaves like if it was
b36de7d0 85 // expecting char*, not wchar_t* input. We have to use DrawStateA
136cb3c7
VS
86 // explicitly.
87
88 if ( wxUsingUnicowsDll() )
89 {
2b5f62a0 90 return DrawStateA((HDC)dc, (HBRUSH)br, (DRAWSTATEPROC)outputFunc,
136cb3c7
VS
91 (LPARAM)(const char*)
92 wxConvLocal.cWX2MB((const wxChar*)lData),
93 wData, x, y, cx, cy, flags);
94 }
95 else
96 {
b36de7d0 97 return DrawStateW((HDC)dc, (HBRUSH)br, (DRAWSTATEPROC)outputFunc,
136cb3c7
VS
98 lData, wData, x, y, cx, cy, flags);
99 }
100}
101
102static void wxFixOPENFILENAME(LPOPENFILENAME ofn)
103{
104#ifdef OFN_EXPLORER
b36de7d0
RD
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
136cb3c7 107 // the last component of directory name. This bug is known to MSLU
b36de7d0 108 // developers, but they are not going to fix it: "this is a true
136cb3c7
VS
109 // limitation, that we have decided to live with" and "working
110 // harder on this case just did not seem worth the effort"...
111 //
112 // Our only option is to try to fix it ourselves:
113
114 if ( (ofn->Flags & OFN_ALLOWMULTISELECT) &&
115 ofn->lpstrFile[ofn->nFileOffset-1] != wxT('\0') )
116 {
da865fdd 117 if ( wxDirExists(ofn->lpstrFile) )
136cb3c7
VS
118 {
119 // 1st component is dir => multiple files selected
120 ofn->nFileOffset = wxStrlen(ofn->lpstrFile)+1;
121 }
122 }
6dad7fff 123#endif // OFN_EXPLORER
136cb3c7
VS
124}
125
2679196c 126WXDLLEXPORT int wxMSLU_GetOpenFileNameW(void *ofn)
136cb3c7 127{
d9628647 128 int ret = GetOpenFileName((LPOPENFILENAME)ofn);
136cb3c7
VS
129 if ( wxUsingUnicowsDll() && ret != 0 )
130 wxFixOPENFILENAME((LPOPENFILENAME)ofn);
131 return ret;
132}
133
2679196c 134WXDLLEXPORT int wxMSLU_GetSaveFileNameW(void *ofn)
136cb3c7 135{
d9628647 136 int ret = GetSaveFileName((LPOPENFILENAME)ofn);
136cb3c7
VS
137 if ( wxUsingUnicowsDll() && ret != 0 )
138 wxFixOPENFILENAME((LPOPENFILENAME)ofn);
139 return ret;
140}
141
142#endif // wxUSE_GUI
143
144//------------------------------------------------------------------------
145// Missing libc file manipulation functions in Win9x
146//------------------------------------------------------------------------
147
ec67cff1 148#if wxUSE_BASE
e2478fde 149
52de37c7
VS
150WXDLLIMPEXP_BASE int wxMSLU__wrename(const wchar_t *oldname,
151 const wchar_t *newname)
136cb3c7
VS
152{
153 if ( wxUsingUnicowsDll() )
154 return rename(wxConvFile.cWX2MB(oldname), wxConvFile.cWX2MB(newname));
155 else
52de37c7 156 return _wrename(oldname, newname);
136cb3c7
VS
157}
158
52de37c7 159WXDLLIMPEXP_BASE int wxMSLU__wremove(const wchar_t *name)
136cb3c7
VS
160{
161 if ( wxUsingUnicowsDll() )
162 return remove(wxConvFile.cWX2MB(name));
163 else
52de37c7 164 return _wremove(name);
136cb3c7
VS
165}
166
52de37c7 167WXDLLIMPEXP_BASE FILE* wxMSLU__wfopen(const wchar_t *name,const wchar_t* mode)
cf9d4c67
RR
168{
169 if ( wxUsingUnicowsDll() )
170 return fopen(wxConvFile.cWX2MB(name),wxConvFile.cWX2MB(mode));
171 else
52de37c7
VS
172 return _wfopen(name,mode);
173}
174
175WXDLLIMPEXP_BASE FILE* wxMSLU__wfreopen(const wchar_t *name,
176 const wchar_t* mode,
177 FILE *stream)
178{
179 if ( wxUsingUnicowsDll() )
180 return freopen(wxConvFile.cWX2MB(name), wxConvFile.cWX2MB(mode), stream);
181 else
182 return _wfreopen(name, mode, stream);
cf9d4c67
RR
183}
184
136cb3c7
VS
185#if defined( __VISUALC__ ) \
186 || ( defined(__MINGW32__) && wxCHECK_W32API_VERSION( 0, 5 ) ) \
a3bb1d14
CE
187 || ( defined(__MWERKS__) && defined(__WXMSW__) ) \
188 || ( defined(__BORLANDC__) && (__BORLANDC__ > 0x460) )
136cb3c7 189
52de37c7 190WXDLLIMPEXP_BASE int wxMSLU__wopen(const wchar_t *name, int flags, int mode)
136cb3c7
VS
191{
192 if ( wxUsingUnicowsDll() )
a3bb1d14
CE
193#ifdef __BORLANDC__
194 return open(wxConvFile.cWX2MB(name), flags, mode);
195#else
136cb3c7 196 return _open(wxConvFile.cWX2MB(name), flags, mode);
a3bb1d14 197#endif
136cb3c7
VS
198 else
199 return _wopen(name, flags, mode);
200}
201
52de37c7 202WXDLLIMPEXP_BASE int wxMSLU__waccess(const wchar_t *name, int mode)
136cb3c7
VS
203{
204 if ( wxUsingUnicowsDll() )
205 return _access(wxConvFile.cWX2MB(name), mode);
206 else
207 return _waccess(name, mode);
208}
209
52de37c7 210WXDLLIMPEXP_BASE int wxMSLU__wmkdir(const wchar_t *name)
136cb3c7
VS
211{
212 if ( wxUsingUnicowsDll() )
213 return _mkdir(wxConvFile.cWX2MB(name));
214 else
215 return _wmkdir(name);
216}
217
52de37c7 218WXDLLIMPEXP_BASE int wxMSLU__wrmdir(const wchar_t *name)
136cb3c7
VS
219{
220 if ( wxUsingUnicowsDll() )
221 return _rmdir(wxConvFile.cWX2MB(name));
222 else
223 return _wrmdir(name);
224}
225
52de37c7 226WXDLLIMPEXP_BASE int wxMSLU__wstat(const wchar_t *name, struct _stat *buffer)
136cb3c7
VS
227{
228 if ( wxUsingUnicowsDll() )
229 return _stat((const char*)wxConvFile.cWX2MB(name), buffer);
230 else
231 return _wstat(name, buffer);
232}
233
8792cb73 234#ifdef __BORLANDC__
6dad7fff 235//here _stati64 is defined as stati64, see wx/filefn.h
8792cb73 236#undef _stati64
52de37c7 237WXDLLIMPEXP_BASE int wxMSLU__wstati64(const wchar_t *name, struct _stati64 *buffer)
8792cb73
CE
238 {
239 if ( wxUsingUnicowsDll() )
240 return _stati64((const char*)wxConvFile.cWX2MB(name), (stati64 *) buffer);
241 else
242 return _wstati64(name, (stati64 *) buffer);
243}
244#else
52de37c7 245WXDLLIMPEXP_BASE int wxMSLU__wstati64(const wchar_t *name, struct _stati64 *buffer)
6294ac2e
VZ
246{
247 if ( wxUsingUnicowsDll() )
248 return _stati64((const char*)wxConvFile.cWX2MB(name), buffer);
249 else
250 return _wstati64(name, buffer);
251}
8792cb73 252#endif //__BORLANDC__
6294ac2e 253
e2478fde
VZ
254#endif // compilers having wopen() &c
255
ec67cff1 256#endif // wxUSE_BASE
136cb3c7
VS
257
258#endif // wxUSE_UNICODE_MSLU