]> git.saurik.com Git - wxWidgets.git/blame - src/msw/mslu.cpp
forwarding style changes to documentViews, see #14578
[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
d5e71e81
VZ
24#define wxHAS_HUGE_FILES
25
b057f88a 26//------------------------------------------------------------------------
7eb872f4
VS
27// Check for use of MSLU
28//------------------------------------------------------------------------
29
30#if wxUSE_BASE
31
32bool WXDLLIMPEXP_BASE wxUsingUnicowsDll()
33{
34#if wxUSE_UNICODE_MSLU
406d283a 35 return (wxGetOsVersion() == wxOS_WINDOWS_9X);
7eb872f4
VS
36#else
37 return false;
38#endif
39}
40
41#endif // wxUSE_BASE
42
b057f88a 43
45f410f2 44#if wxUSE_UNICODE_MSLU
136cb3c7
VS
45
46//------------------------------------------------------------------------
47//
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.
53//
b36de7d0 54// Moreover, there are bugs in unicows.dll, of course. We have to
136cb3c7
VS
55// workaround them, too.
56//
57//------------------------------------------------------------------------
58
59#include "wx/msw/private.h"
60#include "wx/msw/mslu.h"
61
62#include <stdio.h>
63#include <io.h>
b36de7d0 64#include <sys/stat.h>
136cb3c7 65
d9628647
VS
66#ifdef __VISUALC__
67 #include <direct.h>
68#endif
136cb3c7 69
6dad7fff 70// Undef redirection macros defined in wx/msw/wrapwin.h:
136cb3c7
VS
71#undef DrawStateW
72#undef GetOpenFileNameW
73#undef GetSaveFileNameW
74
75//------------------------------------------------------------------------
76// Wrongly implemented functions from unicows.dll
77//------------------------------------------------------------------------
78
79#if wxUSE_GUI
80
2679196c
RD
81WXDLLEXPORT int wxMSLU_DrawStateW(WXHDC dc, WXHBRUSH br, WXFARPROC outputFunc,
82 WXLPARAM lData, WXWPARAM wData,
83 int x, int y, int cx, int cy,
84 unsigned int flags)
136cb3c7
VS
85{
86 // VS: There's yet another bug in MSLU: DrawStateW behaves like if it was
b36de7d0 87 // expecting char*, not wchar_t* input. We have to use DrawStateA
136cb3c7
VS
88 // explicitly.
89
90 if ( wxUsingUnicowsDll() )
91 {
2b5f62a0 92 return DrawStateA((HDC)dc, (HBRUSH)br, (DRAWSTATEPROC)outputFunc,
136cb3c7
VS
93 (LPARAM)(const char*)
94 wxConvLocal.cWX2MB((const wxChar*)lData),
95 wData, x, y, cx, cy, flags);
96 }
97 else
98 {
b36de7d0 99 return DrawStateW((HDC)dc, (HBRUSH)br, (DRAWSTATEPROC)outputFunc,
136cb3c7
VS
100 lData, wData, x, y, cx, cy, flags);
101 }
102}
103
104static void wxFixOPENFILENAME(LPOPENFILENAME ofn)
105{
106#ifdef OFN_EXPLORER
b36de7d0
RD
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
136cb3c7 109 // the last component of directory name. This bug is known to MSLU
b36de7d0 110 // developers, but they are not going to fix it: "this is a true
136cb3c7
VS
111 // limitation, that we have decided to live with" and "working
112 // harder on this case just did not seem worth the effort"...
113 //
114 // Our only option is to try to fix it ourselves:
115
116 if ( (ofn->Flags & OFN_ALLOWMULTISELECT) &&
117 ofn->lpstrFile[ofn->nFileOffset-1] != wxT('\0') )
118 {
da865fdd 119 if ( wxDirExists(ofn->lpstrFile) )
136cb3c7
VS
120 {
121 // 1st component is dir => multiple files selected
122 ofn->nFileOffset = wxStrlen(ofn->lpstrFile)+1;
123 }
124 }
6dad7fff 125#endif // OFN_EXPLORER
136cb3c7
VS
126}
127
2679196c 128WXDLLEXPORT int wxMSLU_GetOpenFileNameW(void *ofn)
136cb3c7 129{
d9628647 130 int ret = GetOpenFileName((LPOPENFILENAME)ofn);
136cb3c7
VS
131 if ( wxUsingUnicowsDll() && ret != 0 )
132 wxFixOPENFILENAME((LPOPENFILENAME)ofn);
133 return ret;
134}
135
2679196c 136WXDLLEXPORT int wxMSLU_GetSaveFileNameW(void *ofn)
136cb3c7 137{
d9628647 138 int ret = GetSaveFileName((LPOPENFILENAME)ofn);
136cb3c7
VS
139 if ( wxUsingUnicowsDll() && ret != 0 )
140 wxFixOPENFILENAME((LPOPENFILENAME)ofn);
141 return ret;
142}
143
144#endif // wxUSE_GUI
145
146//------------------------------------------------------------------------
147// Missing libc file manipulation functions in Win9x
148//------------------------------------------------------------------------
149
ec67cff1 150#if wxUSE_BASE
e2478fde 151
52de37c7
VS
152WXDLLIMPEXP_BASE int wxMSLU__wrename(const wchar_t *oldname,
153 const wchar_t *newname)
136cb3c7
VS
154{
155 if ( wxUsingUnicowsDll() )
156 return rename(wxConvFile.cWX2MB(oldname), wxConvFile.cWX2MB(newname));
157 else
52de37c7 158 return _wrename(oldname, newname);
136cb3c7
VS
159}
160
52de37c7 161WXDLLIMPEXP_BASE int wxMSLU__wremove(const wchar_t *name)
136cb3c7
VS
162{
163 if ( wxUsingUnicowsDll() )
164 return remove(wxConvFile.cWX2MB(name));
165 else
52de37c7 166 return _wremove(name);
136cb3c7
VS
167}
168
52de37c7 169WXDLLIMPEXP_BASE FILE* wxMSLU__wfopen(const wchar_t *name,const wchar_t* mode)
cf9d4c67
RR
170{
171 if ( wxUsingUnicowsDll() )
172 return fopen(wxConvFile.cWX2MB(name),wxConvFile.cWX2MB(mode));
173 else
52de37c7
VS
174 return _wfopen(name,mode);
175}
176
177WXDLLIMPEXP_BASE FILE* wxMSLU__wfreopen(const wchar_t *name,
178 const wchar_t* mode,
179 FILE *stream)
180{
181 if ( wxUsingUnicowsDll() )
182 return freopen(wxConvFile.cWX2MB(name), wxConvFile.cWX2MB(mode), stream);
183 else
184 return _wfreopen(name, mode, stream);
cf9d4c67
RR
185}
186
52de37c7 187WXDLLIMPEXP_BASE int wxMSLU__wopen(const wchar_t *name, int flags, int mode)
136cb3c7
VS
188{
189 if ( wxUsingUnicowsDll() )
d5e71e81 190 return wxCRT_OpenA(wxConvFile.cWX2MB(name), flags, mode);
136cb3c7 191 else
d5e71e81 192 return wxCRT_OpenW(name, flags, mode);
136cb3c7
VS
193}
194
52de37c7 195WXDLLIMPEXP_BASE int wxMSLU__waccess(const wchar_t *name, int mode)
136cb3c7
VS
196{
197 if ( wxUsingUnicowsDll() )
d5e71e81 198 return wxCRT_AccessA(wxConvFile.cWX2MB(name), mode);
136cb3c7 199 else
d5e71e81 200 return wxCRT_AccessW(name, mode);
136cb3c7
VS
201}
202
52de37c7 203WXDLLIMPEXP_BASE int wxMSLU__wmkdir(const wchar_t *name)
136cb3c7
VS
204{
205 if ( wxUsingUnicowsDll() )
d5e71e81 206 return wxCRT_MkDirA(wxConvFile.cWX2MB(name));
136cb3c7 207 else
d5e71e81 208 return wxCRT_MkDirW(name);
136cb3c7
VS
209}
210
52de37c7 211WXDLLIMPEXP_BASE int wxMSLU__wrmdir(const wchar_t *name)
136cb3c7
VS
212{
213 if ( wxUsingUnicowsDll() )
d5e71e81 214 return wxCRT_RmDirA(wxConvFile.cWX2MB(name));
136cb3c7 215 else
d5e71e81 216 return wxCRT_RmDirW(name);
136cb3c7
VS
217}
218
4bf3e3a7 219WXDLLIMPEXP_BASE int wxMSLU__wstat(const wchar_t *name, wxStructStat *buffer)
6294ac2e
VZ
220{
221 if ( wxUsingUnicowsDll() )
d5e71e81 222 return wxCRT_StatA((const char*)wxConvFile.cWX2MB(name), buffer);
6294ac2e 223 else
d5e71e81 224 return wxCRT_StatW(name, buffer);
6294ac2e 225}
4bf3e3a7 226
ec67cff1 227#endif // wxUSE_BASE
136cb3c7
VS
228
229#endif // wxUSE_UNICODE_MSLU