]> git.saurik.com Git - wxWidgets.git/blame - src/mgl/utils.cpp
cleanup image after application
[wxWidgets.git] / src / mgl / utils.cpp
CommitLineData
32b8ec41
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: utils.cpp
3// Purpose:
4// Author: Vaclav Slavik
5// Id: $Id$
c41c20a5 6// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
65571936 7// Licence: wxWindows licence
32b8ec41
VZ
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"
cd478a95 21#include "wx/apptrait.h"
32b8ec41 22#include "wx/log.h"
32b8ec41
VZ
23#include "wx/process.h"
24
25#include <stdarg.h>
26#include <string.h>
27#include <sys/stat.h>
28#include <sys/types.h>
29#include <unistd.h>
30#include <mgraph.hpp>
31
32#ifdef __UNIX__
33#include "wx/unix/execute.h"
34#endif
35
a4bbc9f7
VS
36#include "wx/mgl/private.h"
37
32b8ec41
VZ
38//----------------------------------------------------------------------------
39// misc.
40//----------------------------------------------------------------------------
41
42void wxBell()
43{
44 // FIXME_MGL
45}
46
9210a48a
VS
47
48#ifdef __DOS__
49// VS: this should be in utilsdos.cpp, but since there will hardly ever
50// be a non-MGL MS-DOS port...
51
52void wxSleep(int nSecs)
53{
54 wxUsleep(1000 * nSecs);
55}
56
57void wxUsleep(unsigned long milliseconds)
58{
59 PM_sleep(milliseconds);
60}
61
62
63bool wxGetEnv(const wxString& var, wxString *value)
64{
65 // wxGetenv is defined as getenv()
66 wxChar *p = wxGetenv(var);
67 if ( !p )
68 return FALSE;
69
70 if ( value )
71 *value = p;
72
73 return TRUE;
74}
75
76bool wxSetEnv(const wxString& variable, const wxChar *value)
77{
9210a48a
VS
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;
9210a48a
VS
90}
91
92const wxChar* wxGetHomeDir(wxString *home)
93{
94 *home = wxT(".");
95 return home->c_str();
96}
97
98const wxChar* wxGetUserHomeDir(wxString *home)
99{
100 *home = wxT(".");
101 return home->c_str();
102}
103
104#if wxUSE_UNICODE
105const wxMB2WXbuf wxGetUserHome(const wxString &user)
106#else // just for binary compatibility -- there is no 'const' here
107wxChar *wxGetUserHome(const wxString &user)
108#endif
109{
110 return wxT(".");
111}
112
113void wxFatalError(const wxString &msg, const wxString &title)
114{
115 if (!title.IsNull())
116 wxFprintf( stderr, wxT("%s "), WXSTRINGCAST(title));
117 PM_fatalError(msg.c_str());
118}
119
120bool wxGetUserId(wxChar *WXUNUSED(buf), int WXUNUSED(sz))
121{
122 wxFAIL_MSG( wxT("wxGetUserId not implemented under MS-DOS!") );
123 return FALSE;
124}
125
126bool wxGetUserName(wxChar *WXUNUSED(buf), int WXUNUSED(sz))
127{
128 wxFAIL_MSG( wxT("wxGetUserName not implemented under MS-DOS!") );
129 return FALSE;
130}
131
132bool wxGetHostName(wxChar *WXUNUSED(buf), int WXUNUSED(sz))
133{
134 wxFAIL_MSG( wxT("wxGetHostName not implemented under MS-DOS!") );
135 return FALSE;
136}
137
138bool wxGetFullHostName(wxChar *WXUNUSED(buf), int WXUNUSED(sz))
139{
140 wxFAIL_MSG( wxT("wxGetFullHostName not implemented under MS-DOS!") );
141 return FALSE;
142}
143
144int wxKill(long WXUNUSED(pid), wxSignal WXUNUSED(sig), wxKillError *WXUNUSED(rc))
145{
146 wxFAIL_MSG( wxT("wxKill not implemented under MS-DOS!") );
147 return 0;
148}
149
0280ab6e 150long wxExecute(const wxString& WXUNUSED(command), int WXUNUSED(flags), wxProcess *WXUNUSED(process))
9210a48a
VS
151{
152 wxFAIL_MSG( wxT("wxExecute not implemented under MS-DOS!") );
153 return 0;
154}
155
0280ab6e 156long wxExecute(char **WXUNUSED(argv), int WXUNUSED(flags), wxProcess *WXUNUSED(process))
9210a48a
VS
157{
158 wxFAIL_MSG( wxT("wxExecute not implemented under MS-DOS!") );
159 return 0;
160}
161
162
163#endif
164
32b8ec41
VZ
165// ----------------------------------------------------------------------------
166// display characterstics
167// ----------------------------------------------------------------------------
168
a4bbc9f7 169void wxDisplaySize(int *width, int *height)
32b8ec41 170{
9210a48a 171 wxASSERT_MSG( g_displayDC, wxT("You must call wxApp::SetDisplayMode before using this function") );
b8c0528d
VS
172 if (width) *width = g_displayDC->sizex()+1;
173 if (height) *height = g_displayDC->sizey()+1;
32b8ec41
VZ
174}
175
7bdc1879 176void wxDisplaySizeMM(int *width, int *height)
32b8ec41 177{
1f43b5c9 178 wxASSERT_MSG( g_displayDC, wxT("You must call wxApp::SetDisplayMode before using this function") );
39578f9c
VS
179
180 int xDPI, yDPI;
181 MGL_getDotsPerInch(&xDPI, &yDPI);
182
2343d81b 183 if ( width )
39578f9c 184 *width = (int)((g_displayDC->sizex()+1) * 25.4 / xDPI);
2343d81b 185 if ( height )
39578f9c 186 *height = (int)((g_displayDC->sizey()+1) * 25.4 / yDPI);
a4bbc9f7
VS
187}
188
7bdc1879 189void wxClientDisplayRect(int *x, int *y, int *width, int *height)
a4bbc9f7 190{
58061670
VS
191 if ( x ) *x = 0;
192 if ( y ) *y = 0;
7bdc1879 193 wxDisplaySize(width, height);
58061670 194 // FIXME_MGL - windowed version needs different handling
32b8ec41
VZ
195}
196
197bool wxColourDisplay()
198{
1f43b5c9 199 wxASSERT_MSG( g_displayDC, wxT("You must call wxApp::SetDisplayMode before using this function") );
32b8ec41
VZ
200
201 return (wxDisplayDepth() > 1);
202}
203
204int wxDisplayDepth()
205{
1f43b5c9 206 wxASSERT_MSG( g_displayDC, wxT("You must call wxApp::SetDisplayMode before using this function") );
32b8ec41
VZ
207
208 return g_displayDC->getBitsPerPixel();
209}
210
1c53456f
VS
211#if wxUSE_GUI
212
752464f9 213wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo()
32b8ec41 214{
752464f9
VS
215 static wxToolkitInfo info;
216 info.shortName = _T("mgluniv");
217 info.name = _T("wxMGL");
218 info.versionMajor = MGL_RELEASE_MAJOR;
219 info.versionMinor = MGL_RELEASE_MINOR;
220 info.os = wxGTK;
2343d81b 221#if defined(__UNIX__)
752464f9 222 info.os = wxMGL_UNIX;
2343d81b 223#elif defined(__OS2__)
752464f9 224 info.os = wxMGL_OS2;
2343d81b 225#elif defined(__WIN32__)
752464f9 226 info.os = wxMGL_WIN32;
a246f95e 227#elif defined(__DOS__)
752464f9 228 info.os = wxMGL_DOS;
a246f95e
VS
229#else
230 #error Platform not supported by wxMGL!
32b8ec41 231#endif
752464f9 232 return info;
32b8ec41
VZ
233}
234
1c53456f
VS
235#endif
236
237wxToolkitInfo& wxConsoleAppTraits::GetToolkitInfo()
238{
239 static wxToolkitInfo info;
240 info.shortName = _T("mglbase");
241 info.versionMajor = MGL_RELEASE_MAJOR;
242 info.versionMinor = MGL_RELEASE_MINOR;
243 info.name = _T("wxBase");
244 info.os = wxGTK;
245#if defined(__UNIX__)
246 info.os = wxMGL_UNIX;
247#elif defined(__OS2__)
248 info.os = wxMGL_OS2;
249#elif defined(__WIN32__)
250 info.os = wxMGL_WIN32;
251#elif defined(__DOS__)
252 info.os = wxMGL_DOS;
253#else
254 #error Platform not supported by wxMGL!
255#endif
256 return info;
257}
32b8ec41 258
7bdc1879
VS
259void wxGetMousePosition(int* x, int* y)
260{
261 MS_getPos(x, y);
262}
263
264wxPoint wxGetMousePosition()
265{
266 wxPoint pt;
267 wxGetMousePosition(&pt.x, &pt.y);
268 return pt;
269}
270
271
272
32b8ec41
VZ
273#ifdef __UNIX__
274
275int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
276{
2343d81b
VS
277 wxFAIL_MSG(wxT("wxAddProcessCallback not implemented in wxMGL!"));
278 return 0;
32b8ec41
VZ
279#if 0 // FIXME_MGL -do we need it at all?
280 int tag = gdk_input_add(fd,
281 GDK_INPUT_READ,
282 GTK_EndProcessDetector,
283 (gpointer)proc_data);
284
285 return tag;
286#endif
287}
288
289#endif