]> git.saurik.com Git - wxWidgets.git/blob - src/mgl/utils.cpp
7c138f7e4352468a71e0967c590f6429e1dbadc8
[wxWidgets.git] / src / mgl / utils.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: utils.cpp
3 // Purpose:
4 // Author: Vaclav Slavik
5 // Id: $Id$
6 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
12
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16
17 #include "wx/utils.h"
18 #include "wx/string.h"
19
20 #include "wx/intl.h"
21 #include "wx/log.h"
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
35 #include "wx/mgl/private.h"
36
37 //----------------------------------------------------------------------------
38 // misc.
39 //----------------------------------------------------------------------------
40
41 void wxBell()
42 {
43 // FIXME_MGL
44 }
45
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
51 void wxSleep(int nSecs)
52 {
53 wxUsleep(1000 * nSecs);
54 }
55
56 void wxUsleep(unsigned long milliseconds)
57 {
58 PM_sleep(milliseconds);
59 }
60
61
62 bool 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
75 bool 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
96 const wxChar* wxGetHomeDir(wxString *home)
97 {
98 *home = wxT(".");
99 return home->c_str();
100 }
101
102 const wxChar* wxGetUserHomeDir(wxString *home)
103 {
104 *home = wxT(".");
105 return home->c_str();
106 }
107
108 #if wxUSE_UNICODE
109 const wxMB2WXbuf wxGetUserHome(const wxString &user)
110 #else // just for binary compatibility -- there is no 'const' here
111 wxChar *wxGetUserHome(const wxString &user)
112 #endif
113 {
114 return wxT(".");
115 }
116
117 void 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
124 bool wxGetUserId(wxChar *WXUNUSED(buf), int WXUNUSED(sz))
125 {
126 wxFAIL_MSG( wxT("wxGetUserId not implemented under MS-DOS!") );
127 return FALSE;
128 }
129
130 bool wxGetUserName(wxChar *WXUNUSED(buf), int WXUNUSED(sz))
131 {
132 wxFAIL_MSG( wxT("wxGetUserName not implemented under MS-DOS!") );
133 return FALSE;
134 }
135
136 bool wxGetHostName(wxChar *WXUNUSED(buf), int WXUNUSED(sz))
137 {
138 wxFAIL_MSG( wxT("wxGetHostName not implemented under MS-DOS!") );
139 return FALSE;
140 }
141
142 bool wxGetFullHostName(wxChar *WXUNUSED(buf), int WXUNUSED(sz))
143 {
144 wxFAIL_MSG( wxT("wxGetFullHostName not implemented under MS-DOS!") );
145 return FALSE;
146 }
147
148 int 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
154 long 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
160 long 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
169 // ----------------------------------------------------------------------------
170 // display characterstics
171 // ----------------------------------------------------------------------------
172
173 void wxDisplaySize(int *width, int *height)
174 {
175 wxASSERT_MSG( g_displayDC, wxT("You must call wxApp::SetDisplayMode before using this function") );
176 if (width) *width = g_displayDC->sizex()+1;
177 if (height) *height = g_displayDC->sizey()+1;
178 }
179
180 void wxDisplaySizeMM(int *width, int *height)
181 {
182 wxASSERT_MSG( g_displayDC, wxT("You must call wxApp::SetDisplayMode before using this function") );
183 if ( width )
184 *width = (g_displayDC->sizex()+1) * 25/72;
185 if ( height )
186 *height = (g_displayDC->sizey()+1) * 25/72;
187 // FIXME_MGL -- what about returning *real* monitor dimensions?
188 }
189
190 void wxClientDisplayRect(int *x, int *y, int *width, int *height)
191 {
192 if ( x ) *x = 0;
193 if ( y ) *y = 0;
194 wxDisplaySize(width, height);
195 // FIXME_MGL - windowed version needs different handling
196 }
197
198 bool wxColourDisplay()
199 {
200 wxASSERT_MSG( g_displayDC, wxT("You must call wxApp::SetDisplayMode before using this function") );
201
202 return (wxDisplayDepth() > 1);
203 }
204
205 int wxDisplayDepth()
206 {
207 wxASSERT_MSG( g_displayDC, wxT("You must call wxApp::SetDisplayMode before using this function") );
208
209 return g_displayDC->getBitsPerPixel();
210 }
211
212 int wxGetOsVersion(int *majorVsn, int *minorVsn)
213 {
214 if ( majorVsn )
215 *majorVsn = MGL_RELEASE_MAJOR;
216 if ( minorVsn )
217 *minorVsn = MGL_RELEASE_MINOR;
218
219 #if defined(__UNIX__)
220 return wxMGL_UNIX;
221 #elif defined(__OS2__)
222 return wxMGL_OS2;
223 #elif defined(__WIN32__)
224 return wxMGL_WIN32;
225 #elif defined(__DOS__)
226 return wxMGL_DOS;
227 #else
228 #error Platform not supported by wxMGL!
229 #endif
230 }
231
232
233 void wxGetMousePosition(int* x, int* y)
234 {
235 MS_getPos(x, y);
236 }
237
238 wxPoint wxGetMousePosition()
239 {
240 wxPoint pt;
241 wxGetMousePosition(&pt.x, &pt.y);
242 return pt;
243 }
244
245
246
247 #ifdef __UNIX__
248
249 int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
250 {
251 wxFAIL_MSG(wxT("wxAddProcessCallback not implemented in wxMGL!"));
252 return 0;
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