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