]> git.saurik.com Git - wxWidgets.git/blob - src/mgl/utils.cpp
ec8ed4ff07c3a5a07c0302f58666318a5438f79c
[wxWidgets.git] / src / mgl / utils.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: utils.cpp
3 // Purpose:
4 // Author: Vaclav Slavik
5 // Id: $Id$
6 // Copyright: (c) 2001-2002 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/apptrait.h"
22 #include "wx/log.h"
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
36 #include "wx/mgl/private.h"
37
38 //----------------------------------------------------------------------------
39 // misc.
40 //----------------------------------------------------------------------------
41
42 void wxBell()
43 {
44 // FIXME_MGL
45 }
46
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
52 void wxSleep(int nSecs)
53 {
54 wxMilliSleep(1000 * nSecs);
55 }
56
57 void wxMilliSleep(unsigned long milliseconds)
58 {
59 PM_sleep(milliseconds);
60 }
61
62 void wxMicroSleep(unsigned long microseconds)
63 {
64 wxMilliSleep(microseconds/1000);
65 }
66
67 bool wxGetEnv(const wxString& var, wxString *value)
68 {
69 // wxGetenv is defined as getenv()
70 wxChar *p = wxGetenv(var);
71 if ( !p )
72 return FALSE;
73
74 if ( value )
75 *value = p;
76
77 return TRUE;
78 }
79
80 bool wxSetEnv(const wxString& variable, const wxChar *value)
81 {
82 wxString s = variable;
83 if ( value )
84 s << _T('=') << value;
85
86 // transform to ANSI
87 const char *p = s.mb_str();
88
89 // the string will be free()d by libc
90 char *buf = (char *)malloc(strlen(p) + 1);
91 strcpy(buf, p);
92
93 return putenv(buf) == 0;
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), int WXUNUSED(flags))
149 {
150 wxFAIL_MSG( wxT("wxKill not implemented under MS-DOS!") );
151 return 0;
152 }
153
154 long wxExecute(const wxString& WXUNUSED(command), int WXUNUSED(flags), wxProcess *WXUNUSED(process))
155 {
156 wxFAIL_MSG( wxT("wxExecute not implemented under MS-DOS!") );
157 return 0;
158 }
159
160 long wxExecute(char **WXUNUSED(argv), int WXUNUSED(flags), 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
184 int xDPI, yDPI;
185 MGL_getDotsPerInch(&xDPI, &yDPI);
186
187 if ( width )
188 *width = (int)((g_displayDC->sizex()+1) * 25.4 / xDPI);
189 if ( height )
190 *height = (int)((g_displayDC->sizey()+1) * 25.4 / yDPI);
191 }
192
193 void wxClientDisplayRect(int *x, int *y, int *width, int *height)
194 {
195 if ( x ) *x = 0;
196 if ( y ) *y = 0;
197 wxDisplaySize(width, height);
198 // FIXME_MGL - windowed version needs different handling
199 }
200
201 bool wxColourDisplay()
202 {
203 wxASSERT_MSG( g_displayDC, wxT("You must call wxApp::SetDisplayMode before using this function") );
204
205 return (wxDisplayDepth() > 1);
206 }
207
208 int wxDisplayDepth()
209 {
210 wxASSERT_MSG( g_displayDC, wxT("You must call wxApp::SetDisplayMode before using this function") );
211
212 return g_displayDC->getBitsPerPixel();
213 }
214
215 #if wxUSE_GUI
216
217 wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo()
218 {
219 static wxToolkitInfo info;
220 info.shortName = _T("mgluniv");
221 info.name = _T("wxMGL");
222 info.versionMajor = MGL_RELEASE_MAJOR;
223 info.versionMinor = MGL_RELEASE_MINOR;
224 info.os = wxGTK;
225 #if defined(__UNIX__)
226 info.os = wxMGL_UNIX;
227 #elif defined(__OS2__)
228 info.os = wxMGL_OS2;
229 #elif defined(__WIN32__)
230 info.os = wxMGL_WIN32;
231 #elif defined(__DOS__)
232 info.os = wxMGL_DOS;
233 #else
234 #error Platform not supported by wxMGL!
235 #endif
236 return info;
237 }
238
239 #endif
240
241 wxToolkitInfo& wxConsoleAppTraits::GetToolkitInfo()
242 {
243 static wxToolkitInfo info;
244 info.shortName = _T("mglbase");
245 info.versionMajor = MGL_RELEASE_MAJOR;
246 info.versionMinor = MGL_RELEASE_MINOR;
247 info.name = _T("wxBase");
248 info.os = wxGTK;
249 #if defined(__UNIX__)
250 info.os = wxMGL_UNIX;
251 #elif defined(__OS2__)
252 info.os = wxMGL_OS2;
253 #elif defined(__WIN32__)
254 info.os = wxMGL_WIN32;
255 #elif defined(__DOS__)
256 info.os = wxMGL_DOS;
257 #else
258 #error Platform not supported by wxMGL!
259 #endif
260 return info;
261 }
262
263 void wxGetMousePosition(int* x, int* y)
264 {
265 MS_getPos(x, y);
266 }
267
268 wxPoint wxGetMousePosition()
269 {
270 wxPoint pt;
271 wxGetMousePosition(&pt.x, &pt.y);
272 return pt;
273 }
274
275
276
277 #ifdef __UNIX__
278
279 int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
280 {
281 wxFAIL_MSG(wxT("wxAddProcessCallback not implemented in wxMGL!"));
282 return 0;
283 #if 0 // FIXME_MGL -do we need it at all?
284 int tag = gdk_input_add(fd,
285 GDK_INPUT_READ,
286 GTK_EndProcessDetector,
287 (gpointer)proc_data);
288
289 return tag;
290 #endif
291 }
292
293 #endif