]> git.saurik.com Git - wxWidgets.git/blame - src/mgl/utils.cpp
implemented wxDir as pure MGL code
[wxWidgets.git] / src / mgl / utils.cpp
CommitLineData
32b8ec41
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: utils.cpp
3// Purpose:
4// Author: Vaclav Slavik
5// Id: $Id$
8f7b34a8 6// Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
32b8ec41
VZ
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
a246f95e
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
13#ifdef __BORLANDC__
14 #pragma hdrstop
15#endif
16
32b8ec41
VZ
17#include "wx/utils.h"
18#include "wx/string.h"
19
20#include "wx/intl.h"
21#include "wx/log.h"
32b8ec41
VZ
22#include "wx/process.h"
23
24#include <stdarg.h>
25#include <string.h>
26#include <sys/stat.h>
27#include <sys/types.h>
28#include <unistd.h>
29#include <mgraph.hpp>
30
31#ifdef __UNIX__
32#include "wx/unix/execute.h"
33#endif
34
a4bbc9f7
VS
35#include "wx/mgl/private.h"
36
32b8ec41
VZ
37//----------------------------------------------------------------------------
38// misc.
39//----------------------------------------------------------------------------
40
41void wxBell()
42{
43 // FIXME_MGL
44}
45
9210a48a
VS
46
47#ifdef __DOS__
48// VS: this should be in utilsdos.cpp, but since there will hardly ever
49// be a non-MGL MS-DOS port...
50
51void wxSleep(int nSecs)
52{
53 wxUsleep(1000 * nSecs);
54}
55
56void wxUsleep(unsigned long milliseconds)
57{
58 PM_sleep(milliseconds);
59}
60
61
62bool wxGetEnv(const wxString& var, wxString *value)
63{
64 // wxGetenv is defined as getenv()
65 wxChar *p = wxGetenv(var);
66 if ( !p )
67 return FALSE;
68
69 if ( value )
70 *value = p;
71
72 return TRUE;
73}
74
75bool wxSetEnv(const wxString& variable, const wxChar *value)
76{
77#ifdef __WATCOMC__ // has putenv()
78 wxString s = variable;
79 if ( value )
80 s << _T('=') << value;
81
82 // transform to ANSI
83 const char *p = s.mb_str();
84
85 // the string will be free()d by libc
86 char *buf = (char *)malloc(strlen(p) + 1);
87 strcpy(buf, p);
88
89 return putenv(buf) == 0;
90#else // no way to set an env var
91 #error "Don't know how to implement wxSetEnv on this platform!"
92 return FALSE;
93#endif
94}
95
96const wxChar* wxGetHomeDir(wxString *home)
97{
98 *home = wxT(".");
99 return home->c_str();
100}
101
102const wxChar* wxGetUserHomeDir(wxString *home)
103{
104 *home = wxT(".");
105 return home->c_str();
106}
107
108#if wxUSE_UNICODE
109const wxMB2WXbuf wxGetUserHome(const wxString &user)
110#else // just for binary compatibility -- there is no 'const' here
111wxChar *wxGetUserHome(const wxString &user)
112#endif
113{
114 return wxT(".");
115}
116
117void wxFatalError(const wxString &msg, const wxString &title)
118{
119 if (!title.IsNull())
120 wxFprintf( stderr, wxT("%s "), WXSTRINGCAST(title));
121 PM_fatalError(msg.c_str());
122}
123
124bool wxGetUserId(wxChar *WXUNUSED(buf), int WXUNUSED(sz))
125{
126 wxFAIL_MSG( wxT("wxGetUserId not implemented under MS-DOS!") );
127 return FALSE;
128}
129
130bool wxGetUserName(wxChar *WXUNUSED(buf), int WXUNUSED(sz))
131{
132 wxFAIL_MSG( wxT("wxGetUserName not implemented under MS-DOS!") );
133 return FALSE;
134}
135
136bool wxGetHostName(wxChar *WXUNUSED(buf), int WXUNUSED(sz))
137{
138 wxFAIL_MSG( wxT("wxGetHostName not implemented under MS-DOS!") );
139 return FALSE;
140}
141
142bool wxGetFullHostName(wxChar *WXUNUSED(buf), int WXUNUSED(sz))
143{
144 wxFAIL_MSG( wxT("wxGetFullHostName not implemented under MS-DOS!") );
145 return FALSE;
146}
147
148int wxKill(long WXUNUSED(pid), wxSignal WXUNUSED(sig), wxKillError *WXUNUSED(rc))
149{
150 wxFAIL_MSG( wxT("wxKill not implemented under MS-DOS!") );
151 return 0;
152}
153
154long wxExecute(const wxString& WXUNUSED(command), bool WXUNUSED(sync), wxProcess *WXUNUSED(process))
155{
156 wxFAIL_MSG( wxT("wxExecute not implemented under MS-DOS!") );
157 return 0;
158}
159
160long wxExecute(wxChar **WXUNUSED(argv), bool WXUNUSED(sync), wxProcess *WXUNUSED(process))
161{
162 wxFAIL_MSG( wxT("wxExecute not implemented under MS-DOS!") );
163 return 0;
164}
165
166
167#endif
168
32b8ec41
VZ
169// ----------------------------------------------------------------------------
170// display characterstics
171// ----------------------------------------------------------------------------
172
a4bbc9f7 173void wxDisplaySize(int *width, int *height)
32b8ec41 174{
9210a48a 175 wxASSERT_MSG( g_displayDC, wxT("You must call wxApp::SetDisplayMode before using this function") );
b8c0528d
VS
176 if (width) *width = g_displayDC->sizex()+1;
177 if (height) *height = g_displayDC->sizey()+1;
32b8ec41
VZ
178}
179
7bdc1879 180void wxDisplaySizeMM(int *width, int *height)
32b8ec41 181{
1f43b5c9 182 wxASSERT_MSG( g_displayDC, wxT("You must call wxApp::SetDisplayMode before using this function") );
2343d81b 183 if ( width )
b8c0528d 184 *width = (g_displayDC->sizex()+1) * 25/72;
2343d81b 185 if ( height )
b8c0528d 186 *height = (g_displayDC->sizey()+1) * 25/72;
7bdc1879 187 // FIXME_MGL -- what about returning *real* monitor dimensions?
a4bbc9f7
VS
188}
189
7bdc1879 190void wxClientDisplayRect(int *x, int *y, int *width, int *height)
a4bbc9f7 191{
58061670
VS
192 if ( x ) *x = 0;
193 if ( y ) *y = 0;
7bdc1879 194 wxDisplaySize(width, height);
58061670 195 // FIXME_MGL - windowed version needs different handling
32b8ec41
VZ
196}
197
198bool wxColourDisplay()
199{
1f43b5c9 200 wxASSERT_MSG( g_displayDC, wxT("You must call wxApp::SetDisplayMode before using this function") );
32b8ec41
VZ
201
202 return (wxDisplayDepth() > 1);
203}
204
205int wxDisplayDepth()
206{
1f43b5c9 207 wxASSERT_MSG( g_displayDC, wxT("You must call wxApp::SetDisplayMode before using this function") );
32b8ec41
VZ
208
209 return g_displayDC->getBitsPerPixel();
210}
211
212int wxGetOsVersion(int *majorVsn, int *minorVsn)
213{
a246f95e
VS
214 if ( majorVsn )
215 *majorVsn = MGL_RELEASE_MAJOR;
216 if ( minorVsn )
217 *minorVsn = MGL_RELEASE_MINOR;
2343d81b
VS
218
219#if defined(__UNIX__)
a246f95e 220 return wxMGL_UNIX;
2343d81b 221#elif defined(__OS2__)
a246f95e 222 return wxMGL_OS2;
2343d81b 223#elif defined(__WIN32__)
a246f95e
VS
224 return wxMGL_WIN32;
225#elif defined(__DOS__)
226 return wxMGL_DOS;
227#else
228 #error Platform not supported by wxMGL!
32b8ec41
VZ
229#endif
230}
231
232
7bdc1879
VS
233void wxGetMousePosition(int* x, int* y)
234{
235 MS_getPos(x, y);
236}
237
238wxPoint wxGetMousePosition()
239{
240 wxPoint pt;
241 wxGetMousePosition(&pt.x, &pt.y);
242 return pt;
243}
244
245
246
32b8ec41
VZ
247#ifdef __UNIX__
248
249int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
250{
2343d81b
VS
251 wxFAIL_MSG(wxT("wxAddProcessCallback not implemented in wxMGL!"));
252 return 0;
32b8ec41
VZ
253#if 0 // FIXME_MGL -do we need it at all?
254 int tag = gdk_input_add(fd,
255 GDK_INPUT_READ,
256 GTK_EndProcessDetector,
257 (gpointer)proc_data);
258
259 return tag;
260#endif
261}
262
263#endif