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