]> git.saurik.com Git - wxWidgets.git/blob - src/mgl/utils.cpp
final sweep over docs - replace & with \&
[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 wxUsleep(1000 * nSecs);
55 }
56
57 void wxUsleep(unsigned long milliseconds)
58 {
59 PM_sleep(milliseconds);
60 }
61
62
63 bool 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
76 bool wxSetEnv(const wxString& variable, const wxChar *value)
77 {
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 }
91
92 const wxChar* wxGetHomeDir(wxString *home)
93 {
94 *home = wxT(".");
95 return home->c_str();
96 }
97
98 const wxChar* wxGetUserHomeDir(wxString *home)
99 {
100 *home = wxT(".");
101 return home->c_str();
102 }
103
104 #if wxUSE_UNICODE
105 const wxMB2WXbuf wxGetUserHome(const wxString &user)
106 #else // just for binary compatibility -- there is no 'const' here
107 wxChar *wxGetUserHome(const wxString &user)
108 #endif
109 {
110 return wxT(".");
111 }
112
113 void 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
120 bool wxGetUserId(wxChar *WXUNUSED(buf), int WXUNUSED(sz))
121 {
122 wxFAIL_MSG( wxT("wxGetUserId not implemented under MS-DOS!") );
123 return FALSE;
124 }
125
126 bool wxGetUserName(wxChar *WXUNUSED(buf), int WXUNUSED(sz))
127 {
128 wxFAIL_MSG( wxT("wxGetUserName not implemented under MS-DOS!") );
129 return FALSE;
130 }
131
132 bool wxGetHostName(wxChar *WXUNUSED(buf), int WXUNUSED(sz))
133 {
134 wxFAIL_MSG( wxT("wxGetHostName not implemented under MS-DOS!") );
135 return FALSE;
136 }
137
138 bool wxGetFullHostName(wxChar *WXUNUSED(buf), int WXUNUSED(sz))
139 {
140 wxFAIL_MSG( wxT("wxGetFullHostName not implemented under MS-DOS!") );
141 return FALSE;
142 }
143
144 int 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
150 long wxExecute(const wxString& WXUNUSED(command), int WXUNUSED(flags), wxProcess *WXUNUSED(process))
151 {
152 wxFAIL_MSG( wxT("wxExecute not implemented under MS-DOS!") );
153 return 0;
154 }
155
156 long wxExecute(char **WXUNUSED(argv), int WXUNUSED(flags), wxProcess *WXUNUSED(process))
157 {
158 wxFAIL_MSG( wxT("wxExecute not implemented under MS-DOS!") );
159 return 0;
160 }
161
162
163 #endif
164
165 // ----------------------------------------------------------------------------
166 // display characterstics
167 // ----------------------------------------------------------------------------
168
169 void wxDisplaySize(int *width, int *height)
170 {
171 wxASSERT_MSG( g_displayDC, wxT("You must call wxApp::SetDisplayMode before using this function") );
172 if (width) *width = g_displayDC->sizex()+1;
173 if (height) *height = g_displayDC->sizey()+1;
174 }
175
176 void wxDisplaySizeMM(int *width, int *height)
177 {
178 wxASSERT_MSG( g_displayDC, wxT("You must call wxApp::SetDisplayMode before using this function") );
179
180 int xDPI, yDPI;
181 MGL_getDotsPerInch(&xDPI, &yDPI);
182
183 if ( width )
184 *width = (int)((g_displayDC->sizex()+1) * 25.4 / xDPI);
185 if ( height )
186 *height = (int)((g_displayDC->sizey()+1) * 25.4 / yDPI);
187 }
188
189 void wxClientDisplayRect(int *x, int *y, int *width, int *height)
190 {
191 if ( x ) *x = 0;
192 if ( y ) *y = 0;
193 wxDisplaySize(width, height);
194 // FIXME_MGL - windowed version needs different handling
195 }
196
197 bool wxColourDisplay()
198 {
199 wxASSERT_MSG( g_displayDC, wxT("You must call wxApp::SetDisplayMode before using this function") );
200
201 return (wxDisplayDepth() > 1);
202 }
203
204 int wxDisplayDepth()
205 {
206 wxASSERT_MSG( g_displayDC, wxT("You must call wxApp::SetDisplayMode before using this function") );
207
208 return g_displayDC->getBitsPerPixel();
209 }
210
211 #if wxUSE_GUI
212
213 wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo()
214 {
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;
221 #if defined(__UNIX__)
222 info.os = wxMGL_UNIX;
223 #elif defined(__OS2__)
224 info.os = wxMGL_OS2;
225 #elif defined(__WIN32__)
226 info.os = wxMGL_WIN32;
227 #elif defined(__DOS__)
228 info.os = wxMGL_DOS;
229 #else
230 #error Platform not supported by wxMGL!
231 #endif
232 return info;
233 }
234
235 #endif
236
237 wxToolkitInfo& 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 }
258
259 void wxGetMousePosition(int* x, int* y)
260 {
261 MS_getPos(x, y);
262 }
263
264 wxPoint wxGetMousePosition()
265 {
266 wxPoint pt;
267 wxGetMousePosition(&pt.x, &pt.y);
268 return pt;
269 }
270
271
272
273 #ifdef __UNIX__
274
275 int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
276 {
277 wxFAIL_MSG(wxT("wxAddProcessCallback not implemented in wxMGL!"));
278 return 0;
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