]> git.saurik.com Git - wxWidgets.git/blob - src/mgl/utils.cpp
cleaning up the mess created by the FloodFill patch
[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/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 wxString s = variable;
78 if ( value )
79 s << _T('=') << value;
80
81 // transform to ANSI
82 const char *p = s.mb_str();
83
84 // the string will be free()d by libc
85 char *buf = (char *)malloc(strlen(p) + 1);
86 strcpy(buf, p);
87
88 return putenv(buf) == 0;
89 }
90
91 const wxChar* wxGetHomeDir(wxString *home)
92 {
93 *home = wxT(".");
94 return home->c_str();
95 }
96
97 const wxChar* wxGetUserHomeDir(wxString *home)
98 {
99 *home = wxT(".");
100 return home->c_str();
101 }
102
103 #if wxUSE_UNICODE
104 const wxMB2WXbuf wxGetUserHome(const wxString &user)
105 #else // just for binary compatibility -- there is no 'const' here
106 wxChar *wxGetUserHome(const wxString &user)
107 #endif
108 {
109 return wxT(".");
110 }
111
112 void wxFatalError(const wxString &msg, const wxString &title)
113 {
114 if (!title.IsNull())
115 wxFprintf( stderr, wxT("%s "), WXSTRINGCAST(title));
116 PM_fatalError(msg.c_str());
117 }
118
119 bool wxGetUserId(wxChar *WXUNUSED(buf), int WXUNUSED(sz))
120 {
121 wxFAIL_MSG( wxT("wxGetUserId not implemented under MS-DOS!") );
122 return FALSE;
123 }
124
125 bool wxGetUserName(wxChar *WXUNUSED(buf), int WXUNUSED(sz))
126 {
127 wxFAIL_MSG( wxT("wxGetUserName not implemented under MS-DOS!") );
128 return FALSE;
129 }
130
131 bool wxGetHostName(wxChar *WXUNUSED(buf), int WXUNUSED(sz))
132 {
133 wxFAIL_MSG( wxT("wxGetHostName not implemented under MS-DOS!") );
134 return FALSE;
135 }
136
137 bool wxGetFullHostName(wxChar *WXUNUSED(buf), int WXUNUSED(sz))
138 {
139 wxFAIL_MSG( wxT("wxGetFullHostName not implemented under MS-DOS!") );
140 return FALSE;
141 }
142
143 int wxKill(long WXUNUSED(pid), wxSignal WXUNUSED(sig), wxKillError *WXUNUSED(rc))
144 {
145 wxFAIL_MSG( wxT("wxKill not implemented under MS-DOS!") );
146 return 0;
147 }
148
149 long wxExecute(const wxString& WXUNUSED(command), bool WXUNUSED(sync), wxProcess *WXUNUSED(process))
150 {
151 wxFAIL_MSG( wxT("wxExecute not implemented under MS-DOS!") );
152 return 0;
153 }
154
155 long wxExecute(wxChar **WXUNUSED(argv), bool WXUNUSED(sync), wxProcess *WXUNUSED(process))
156 {
157 wxFAIL_MSG( wxT("wxExecute not implemented under MS-DOS!") );
158 return 0;
159 }
160
161
162 #endif
163
164 // ----------------------------------------------------------------------------
165 // display characterstics
166 // ----------------------------------------------------------------------------
167
168 void wxDisplaySize(int *width, int *height)
169 {
170 wxASSERT_MSG( g_displayDC, wxT("You must call wxApp::SetDisplayMode before using this function") );
171 if (width) *width = g_displayDC->sizex()+1;
172 if (height) *height = g_displayDC->sizey()+1;
173 }
174
175 void wxDisplaySizeMM(int *width, int *height)
176 {
177 wxASSERT_MSG( g_displayDC, wxT("You must call wxApp::SetDisplayMode before using this function") );
178
179 int xDPI, yDPI;
180 MGL_getDotsPerInch(&xDPI, &yDPI);
181
182 if ( width )
183 *width = (int)((g_displayDC->sizex()+1) * 25.4 / xDPI);
184 if ( height )
185 *height = (int)((g_displayDC->sizey()+1) * 25.4 / yDPI);
186 }
187
188 void wxClientDisplayRect(int *x, int *y, int *width, int *height)
189 {
190 if ( x ) *x = 0;
191 if ( y ) *y = 0;
192 wxDisplaySize(width, height);
193 // FIXME_MGL - windowed version needs different handling
194 }
195
196 bool wxColourDisplay()
197 {
198 wxASSERT_MSG( g_displayDC, wxT("You must call wxApp::SetDisplayMode before using this function") );
199
200 return (wxDisplayDepth() > 1);
201 }
202
203 int wxDisplayDepth()
204 {
205 wxASSERT_MSG( g_displayDC, wxT("You must call wxApp::SetDisplayMode before using this function") );
206
207 return g_displayDC->getBitsPerPixel();
208 }
209
210 int wxGetOsVersion(int *majorVsn, int *minorVsn)
211 {
212 if ( majorVsn )
213 *majorVsn = MGL_RELEASE_MAJOR;
214 if ( minorVsn )
215 *minorVsn = MGL_RELEASE_MINOR;
216
217 #if defined(__UNIX__)
218 return wxMGL_UNIX;
219 #elif defined(__OS2__)
220 return wxMGL_OS2;
221 #elif defined(__WIN32__)
222 return wxMGL_WIN32;
223 #elif defined(__DOS__)
224 return wxMGL_DOS;
225 #else
226 #error Platform not supported by wxMGL!
227 #endif
228 }
229
230
231 void wxGetMousePosition(int* x, int* y)
232 {
233 MS_getPos(x, y);
234 }
235
236 wxPoint wxGetMousePosition()
237 {
238 wxPoint pt;
239 wxGetMousePosition(&pt.x, &pt.y);
240 return pt;
241 }
242
243
244
245 #ifdef __UNIX__
246
247 int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
248 {
249 wxFAIL_MSG(wxT("wxAddProcessCallback not implemented in wxMGL!"));
250 return 0;
251 #if 0 // FIXME_MGL -do we need it at all?
252 int tag = gdk_input_add(fd,
253 GDK_INPUT_READ,
254 GTK_EndProcessDetector,
255 (gpointer)proc_data);
256
257 return tag;
258 #endif
259 }
260
261 #endif