]> git.saurik.com Git - wxWidgets.git/blame - src/msw/mslu.cpp
Set flags and libs for using unicows if MSLU=1
[wxWidgets.git] / src / msw / mslu.cpp
CommitLineData
136cb3c7
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: msw/mslu.cpp
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
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24 #include "wx/defs.h"
25#endif
26
27#if wxUSE_UNICODE_MSLU
28
29//------------------------------------------------------------------------
30//
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.
36//
b36de7d0 37// Moreover, there are bugs in unicows.dll, of course. We have to
136cb3c7
VS
38// workaround them, too.
39//
40//------------------------------------------------------------------------
41
42#include "wx/msw/private.h"
43#include "wx/msw/mslu.h"
44
45#include <stdio.h>
46#include <io.h>
b36de7d0 47#include <sys/stat.h>
136cb3c7
VS
48
49#ifdef __GNUWIN32__
50 #include <wchar.h>
136cb3c7
VS
51#endif
52
d9628647
VS
53#ifdef __VISUALC__
54 #include <direct.h>
55#endif
136cb3c7
VS
56
57// Undef redirection macros defined in wx/msw/mslu.h:
58#undef DrawStateW
59#undef GetOpenFileNameW
60#undef GetSaveFileNameW
61
62//------------------------------------------------------------------------
63// Wrongly implemented functions from unicows.dll
64//------------------------------------------------------------------------
65
66#if wxUSE_GUI
67
b36de7d0
RD
68WXDLLEXPORT int wxMSLU_DrawStateW(WXHDC dc, WXHBRUSH br, WXFARPROC outputFunc,
69 WXLPARAM lData, WXWPARAM wData,
70 int x, int y, int cx, int cy,
136cb3c7
VS
71 unsigned int flags)
72{
73 // VS: There's yet another bug in MSLU: DrawStateW behaves like if it was
b36de7d0 74 // expecting char*, not wchar_t* input. We have to use DrawStateA
136cb3c7
VS
75 // explicitly.
76
77 if ( wxUsingUnicowsDll() )
78 {
79 return DrawStateA((HDC)dc, (HBRUSH)br, (DRAWSTATEPROC)outputFunc,
80 (LPARAM)(const char*)
81 wxConvLocal.cWX2MB((const wxChar*)lData),
82 wData, x, y, cx, cy, flags);
83 }
84 else
85 {
b36de7d0 86 return DrawStateW((HDC)dc, (HBRUSH)br, (DRAWSTATEPROC)outputFunc,
136cb3c7
VS
87 lData, wData, x, y, cx, cy, flags);
88 }
89}
90
91static void wxFixOPENFILENAME(LPOPENFILENAME ofn)
92{
93#ifdef OFN_EXPLORER
b36de7d0
RD
94 // VS: there's a bug in unicows.dll - when multiple files are selected,
95 // of.nFileOffset doesn't point to the first filename but rather to
136cb3c7 96 // the last component of directory name. This bug is known to MSLU
b36de7d0 97 // developers, but they are not going to fix it: "this is a true
136cb3c7
VS
98 // limitation, that we have decided to live with" and "working
99 // harder on this case just did not seem worth the effort"...
100 //
101 // Our only option is to try to fix it ourselves:
102
103 if ( (ofn->Flags & OFN_ALLOWMULTISELECT) &&
104 ofn->lpstrFile[ofn->nFileOffset-1] != wxT('\0') )
105 {
106 if ( wxDirExists(ofn->lpstrFile) )
107 {
108 // 1st component is dir => multiple files selected
109 ofn->nFileOffset = wxStrlen(ofn->lpstrFile)+1;
110 }
111 }
112#endif
113}
114
d9628647 115WXDLLEXPORT int wxMSLU_GetOpenFileNameW(void *ofn)
136cb3c7 116{
d9628647 117 int ret = GetOpenFileName((LPOPENFILENAME)ofn);
136cb3c7
VS
118 if ( wxUsingUnicowsDll() && ret != 0 )
119 wxFixOPENFILENAME((LPOPENFILENAME)ofn);
120 return ret;
121}
122
d9628647 123WXDLLEXPORT int wxMSLU_GetSaveFileNameW(void *ofn)
136cb3c7 124{
d9628647 125 int ret = GetSaveFileName((LPOPENFILENAME)ofn);
136cb3c7
VS
126 if ( wxUsingUnicowsDll() && ret != 0 )
127 wxFixOPENFILENAME((LPOPENFILENAME)ofn);
128 return ret;
129}
130
131#endif // wxUSE_GUI
132
133//------------------------------------------------------------------------
134// Missing libc file manipulation functions in Win9x
135//------------------------------------------------------------------------
136
137WXDLLEXPORT int wxMSLU__trename(const wxChar *oldname, const wxChar *newname)
138{
139 if ( wxUsingUnicowsDll() )
140 return rename(wxConvFile.cWX2MB(oldname), wxConvFile.cWX2MB(newname));
141 else
142 return _trename(oldname, newname);
143}
144
145WXDLLEXPORT int wxMSLU__tremove(const wxChar *name)
146{
147 if ( wxUsingUnicowsDll() )
148 return remove(wxConvFile.cWX2MB(name));
149 else
150 return _tremove(name);
151}
152
153#if defined( __VISUALC__ ) \
154 || ( defined(__MINGW32__) && wxCHECK_W32API_VERSION( 0, 5 ) ) \
155 || ( defined(__MWERKS__) && defined(__WXMSW__) )
156
157WXDLLEXPORT int wxMSLU__wopen(const wxChar *name, int flags, int mode)
158{
159 if ( wxUsingUnicowsDll() )
160 return _open(wxConvFile.cWX2MB(name), flags, mode);
161 else
162 return _wopen(name, flags, mode);
163}
164
165WXDLLEXPORT int wxMSLU__waccess(const wxChar *name, int mode)
166{
167 if ( wxUsingUnicowsDll() )
168 return _access(wxConvFile.cWX2MB(name), mode);
169 else
170 return _waccess(name, mode);
171}
172
173WXDLLEXPORT int wxMSLU__wmkdir(const wxChar *name)
174{
175 if ( wxUsingUnicowsDll() )
176 return _mkdir(wxConvFile.cWX2MB(name));
177 else
178 return _wmkdir(name);
179}
180
181WXDLLEXPORT int wxMSLU__wrmdir(const wxChar *name)
182{
183 if ( wxUsingUnicowsDll() )
184 return _rmdir(wxConvFile.cWX2MB(name));
185 else
186 return _wrmdir(name);
187}
188
189WXDLLEXPORT int wxMSLU__wstat(const wxChar *name, struct _stat *buffer)
190{
191 if ( wxUsingUnicowsDll() )
192 return _stat((const char*)wxConvFile.cWX2MB(name), buffer);
193 else
194 return _wstat(name, buffer);
195}
196
197#endif
198
199#endif // wxUSE_UNICODE_MSLU