]> git.saurik.com Git - wxWidgets.git/blob - src/mgl/utils.cpp
multilib mode compilation fix
[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 int wxGUIAppTraits::GetOSVersion(int *majorVsn, int *minorVsn)
212 {
213 if ( majorVsn )
214 *majorVsn = MGL_RELEASE_MAJOR;
215 if ( minorVsn )
216 *minorVsn = MGL_RELEASE_MINOR;
217
218 #if defined(__UNIX__)
219 return wxMGL_UNIX;
220 #elif defined(__OS2__)
221 return wxMGL_OS2;
222 #elif defined(__WIN32__)
223 return wxMGL_WIN32;
224 #elif defined(__DOS__)
225 return wxMGL_DOS;
226 #else
227 #error Platform not supported by wxMGL!
228 #endif
229 }
230
231
232 void wxGetMousePosition(int* x, int* y)
233 {
234 MS_getPos(x, y);
235 }
236
237 wxPoint wxGetMousePosition()
238 {
239 wxPoint pt;
240 wxGetMousePosition(&pt.x, &pt.y);
241 return pt;
242 }
243
244
245
246 #ifdef __UNIX__
247
248 int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
249 {
250 wxFAIL_MSG(wxT("wxAddProcessCallback not implemented in wxMGL!"));
251 return 0;
252 #if 0 // FIXME_MGL -do we need it at all?
253 int tag = gdk_input_add(fd,
254 GDK_INPUT_READ,
255 GTK_EndProcessDetector,
256 (gpointer)proc_data);
257
258 return tag;
259 #endif
260 }
261
262 #endif