]> git.saurik.com Git - wxWidgets.git/blob - src/motif/utils.cpp
Motif files added.
[wxWidgets.git] / src / motif / utils.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: utils.cpp
3 // Purpose: Various utilities
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 17/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 // Note: this is done in utilscmn.cpp now.
14 // #pragma implementation
15 // #pragma implementation "utils.h"
16 #endif
17
18 #include "wx/setup.h"
19 #include "wx/utils.h"
20 #include "wx/app.h"
21
22 #include <ctype.h>
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <stdarg.h>
28
29 #include <Xm/Xm.h>
30
31 // Get full hostname (eg. DoDo.BSn-Germany.crg.de)
32 bool wxGetHostName(char *buf, int maxSize)
33 {
34 // TODO
35 return FALSE;
36 }
37
38 // Get user ID e.g. jacs
39 bool wxGetUserId(char *buf, int maxSize)
40 {
41 // TODO
42 return FALSE;
43 }
44
45 // Get user name e.g. Julian Smart
46 bool wxGetUserName(char *buf, int maxSize)
47 {
48 // TODO
49 return FALSE;
50 }
51
52 int wxKill(long pid, int sig)
53 {
54 // TODO
55 return 0;
56 }
57
58 //
59 // Execute a program in an Interactive Shell
60 //
61 bool wxShell(const wxString& command)
62 {
63 // TODO
64 return FALSE;
65 }
66
67 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
68 long wxGetFreeMemory()
69 {
70 // TODO
71 return 0;
72 }
73
74 void wxSleep(int nSecs)
75 {
76 // TODO
77 }
78
79 // Consume all events until no more left
80 void wxFlushEvents()
81 {
82 }
83
84 // Output a debug message, in a system dependent fashion.
85 void wxDebugMsg(const char *fmt ...)
86 {
87 va_list ap;
88 static char buffer[512];
89
90 if (!wxTheApp->GetWantDebugOutput())
91 return ;
92
93 va_start(ap, fmt);
94
95 // wvsprintf(buffer,fmt,ap) ;
96 // TODO: output buffer
97
98 va_end(ap);
99 }
100
101 // Non-fatal error: pop up message box and (possibly) continue
102 void wxError(const wxString& msg, const wxString& title)
103 {
104 // TODO
105 wxExit();
106 }
107
108 // Fatal error: pop up message box and abort
109 void wxFatalError(const wxString& msg, const wxString& title)
110 {
111 // TODO
112 }
113
114 // Emit a beeeeeep
115 void wxBell()
116 {
117 // TODO
118 }
119
120 int wxGetOsVersion(int *majorVsn, int *minorVsn)
121 {
122 // TODO
123 return 0;
124 }
125
126 // Reading and writing resources (eg WIN.INI, .Xdefaults)
127 #if USE_RESOURCES
128 bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file)
129 {
130 // TODO
131 return FALSE;
132 }
133
134 bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file)
135 {
136 char buf[50];
137 sprintf(buf, "%.4f", value);
138 return wxWriteResource(section, entry, buf, file);
139 }
140
141 bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file)
142 {
143 char buf[50];
144 sprintf(buf, "%ld", value);
145 return wxWriteResource(section, entry, buf, file);
146 }
147
148 bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file)
149 {
150 char buf[50];
151 sprintf(buf, "%d", value);
152 return wxWriteResource(section, entry, buf, file);
153 }
154
155 bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file)
156 {
157 // TODO
158 return FALSE;
159 }
160
161 bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file)
162 {
163 char *s = NULL;
164 bool succ = wxGetResource(section, entry, (char **)&s, file);
165 if (succ)
166 {
167 *value = (float)strtod(s, NULL);
168 delete[] s;
169 return TRUE;
170 }
171 else return FALSE;
172 }
173
174 bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file)
175 {
176 char *s = NULL;
177 bool succ = wxGetResource(section, entry, (char **)&s, file);
178 if (succ)
179 {
180 *value = strtol(s, NULL, 10);
181 delete[] s;
182 return TRUE;
183 }
184 else return FALSE;
185 }
186
187 bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file)
188 {
189 char *s = NULL;
190 bool succ = wxGetResource(section, entry, (char **)&s, file);
191 if (succ)
192 {
193 *value = (int)strtol(s, NULL, 10);
194 delete[] s;
195 return TRUE;
196 }
197 else return FALSE;
198 }
199 #endif // USE_RESOURCES
200
201 static int wxBusyCursorCount = 0;
202
203 // Set the cursor to the busy cursor for all windows
204 void wxBeginBusyCursor(wxCursor *cursor)
205 {
206 wxBusyCursorCount ++;
207 if (wxBusyCursorCount == 1)
208 {
209 // TODO
210 }
211 else
212 {
213 // TODO
214 }
215 }
216
217 // Restore cursor to normal
218 void wxEndBusyCursor()
219 {
220 if (wxBusyCursorCount == 0)
221 return;
222
223 wxBusyCursorCount --;
224 if (wxBusyCursorCount == 0)
225 {
226 // TODO
227 }
228 }
229
230 // TRUE if we're between the above two calls
231 bool wxIsBusy()
232 {
233 return (wxBusyCursorCount > 0);
234 }
235
236 char *wxGetUserHome (const wxString& user)
237 {
238 // TODO
239 return NULL;
240 }
241
242 // Check whether this window wants to process messages, e.g. Stop button
243 // in long calculations.
244 bool wxCheckForInterrupt(wxWindow *wnd)
245 {
246 // TODO
247 return FALSE;
248 }
249
250 void wxGetMousePosition( int* x, int* y )
251 {
252 // TODO
253 };
254
255 // Return TRUE if we have a colour display
256 bool wxColourDisplay()
257 {
258 // TODO
259 return TRUE;
260 }
261
262 // Returns depth of screen
263 int wxDisplayDepth()
264 {
265 // TODO
266 return 0;
267 }
268
269 // Get size of display
270 void wxDisplaySize(int *width, int *height)
271 {
272 // TODO
273 }
274
275 /* Configurable display in Motif */
276 static WXDisplay *gs_currentDisplay = NULL;
277 static wxString gs_displayName;
278
279 WXDisplay *wxGetDisplay()
280 {
281 if (gs_currentDisplay)
282 return gs_currentDisplay;
283
284 return XtDisplay ((Widget) wxTheApp->GetTopLevelWidget());
285 }
286
287 bool wxSetDisplay(const wxString& display_name)
288 {
289 gs_displayName = display_name;
290
291 if (display_name.IsNull() || display_name.IsEmpty())
292 {
293 gs_currentDisplay = NULL;
294 return TRUE;
295 }
296 else
297 {
298 Cardinal argc = 0;
299
300 Display *display = XtOpenDisplay((XtAppContext) wxTheApp->GetAppContext(),
301 (const char*) display_name,
302 (const char*) wxTheApp->GetAppName(),
303 (const char*) wxTheApp->GetClassName(),
304 NULL,
305 # if XtSpecificationRelease < 5
306 0, &argc, NULL);
307 # else
308 0, (int *)&argc, NULL);
309 # endif
310
311 if (display)
312 {
313 gs_currentDisplay = (WXDisplay*) display;
314 return TRUE;
315 } else
316 return FALSE;
317 }
318 return FALSE;
319 }
320
321 wxString wxGetDisplayName()
322 {
323 return gs_displayName;
324 }