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