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